aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2020-05-12 08:54:40 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2020-05-12 08:54:40 +0300
commit46739772abb75cc1a27ecef6183bfcc65edc3a88 (patch)
tree14c8f2089b842be067f6bee2366f9ed40a10756d
parent54054ba622ed7188074e1792ec85808597e6e028 (diff)
downloadMundus-46739772abb75cc1a27ecef6183bfcc65edc3a88.tar
Mundus-46739772abb75cc1a27ecef6183bfcc65edc3a88.tar.gz
Mundus-46739772abb75cc1a27ecef6183bfcc65edc3a88.zip
Fixed random mob movement and fixed issue, where you couldn't place ladders below yourself.
-rw-r--r--Mundus/Data/SuperLayers/LandContext.cs3
-rw-r--r--Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs3
-rw-r--r--Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs24
3 files changed, 17 insertions, 13 deletions
diff --git a/Mundus/Data/SuperLayers/LandContext.cs b/Mundus/Data/SuperLayers/LandContext.cs
index 7411ea3..26f6f41 100644
--- a/Mundus/Data/SuperLayers/LandContext.cs
+++ b/Mundus/Data/SuperLayers/LandContext.cs
@@ -40,7 +40,6 @@ namespace Mundus.Data.SuperLayers {
public void RemoveMobFromPosition(int yPos, int xPos) {
LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null;
LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1;
-
}
public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) {
var mob = LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos);
@@ -48,7 +47,7 @@ namespace Mundus.Data.SuperLayers {
return mob.Health > 0;
}
- public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) {
+ public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) {
LStructureLayer.Add(new LSPlacedTile(stock_id, health, yPos, xPos));
}
diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs
index 5114a18..07a67c6 100644
--- a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs
+++ b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs
@@ -22,7 +22,8 @@ namespace Mundus.Service.Tiles.Mobs.Controllers {
/// <param name="mapYPos">YPos of target mob</param>
/// <param name="mapXPos">XPos of target mob</param>
public static bool ExistsFightTargetForMob(MobTile mob, int mapYPos, int mapXPos) {
- return mob.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos) != null;
+ return mob.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos) != null &&
+ (mob.YPos != mapYPos && mob.XPos != mapXPos);
}
private const double TAKEN_ENERGY_FROM_FIGHTING = 0.5;
diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs
index bb0c03e..73463a3 100644
--- a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs
+++ b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs
@@ -22,15 +22,19 @@ namespace Mundus.Service.Tiles.Mobs.Controllers {
{
for (int x = 0; x < (int)Values.CurrMapSize; x++)
{
- MobTile mob = LandMobsPresets.GetFromStock(superLayer.GetMobLayerStock(y, x));
+ MobTile mob = LandMobsPresets.GetFromStock(superLayer.GetMobLayerStock(y, x));
if (mob != null) {
+ mob.YPos = y;
+ mob.XPos = x;
+
// Checks validity of RndMovementRate and descides if a mob will move to another tile
if (mob.RndMovementRate > 0 && rnd.Next(0, mob.RndMovementRate) == 1)
{
- int newYPos = rnd.Next(mob.YPos - 1, mob.YPos + 2);
- int newXPos = rnd.Next(mob.XPos - 1, mob.XPos + 2);
-
+ int newYPos = rnd.Next(y - 1, y + 2);
+ int newXPos = rnd.Next(x - 1, x + 2);
+
+ mob.CurrSuperLayer = superLayer;
ChangeMobPosition(mob, newYPos, newXPos, (int)Values.CurrMapSize);
}
}
@@ -130,21 +134,21 @@ namespace Mundus.Service.Tiles.Mobs.Controllers {
else if (HeightController.GetLayerAboveMob(mob).GetMobLayerStock(yPos, xPos) != null && mob.GetType() == typeof(Player)) {
GameEventLogController.AddMessage($"Cannot climb up a superlayer, {HeightController.GetLayerAboveMob(mob).GetMobLayerStock(yPos, xPos)} is blocking the way");
}
-
- mob.YPos = yPos;
+
+ mob.YPos = yPos;
mob.XPos = xPos;
mob.CurrSuperLayer.SetMobAtPosition(mob.stock_id, mob.Health, yPos, xPos);
}
private static bool CanWalkTo(MobTile mob, int yPos, int xPos) {
- //Mobs can only walk on free ground (no structure or mob) or walkable structures
+ //Mobs can only walk on free ground (no structure or mob ; you can walk on the same place you are) or walkable structures
if (StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)) == null) {
- return mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos) == null ||
- LandMobsPresets.GetFromStock(mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos)) == mob;
+ return mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos) == null ||
+ (mob.YPos == yPos && mob.XPos == xPos);
}
else if (StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)).IsWalkable) {
return mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos) == null ||
- LandMobsPresets.GetFromStock(mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos)) == mob;
+ (mob.YPos == yPos && mob.XPos == xPos);
}
return false;
}