protected virtual bool UpdateLocation(IHexGridCell location) { if (!OccupiableLocation(location)) { return(false); } if (Location != null) { AssertHelper.Assert(creatureComponent != null, "Missing creature component", this); bool success = Location.RemoveComponent(creatureComponent); AssertHelper.Assert(success, "Failed to remove creature component", this); } else { creatureComponent = new CreatureComponent(this); } Location = location; Location.AddComponent(creatureComponent); return(true); }
private void CreateBase(int x, int y, bool isPlayer, IDictionary <IHexGridCell, bool> baseTerrains) { IHexGridCell centerBaseTile = HexTiling[x, y]; centerBaseTile.RemoveComponent <CreepComponent>(); centerBaseTile.AddComponent((isPlayer) ? (new PlayerBaseComponent() as ICellComponent) : new EnemyBaseComponent()); baseTerrains.Add(centerBaseTile, isPlayer); foreach (IHexGridCell neighbor in HexTiling.CellNeighbors(centerBaseTile)) { baseTerrains.Add(neighbor, isPlayer); neighbor.RemoveComponent <CreepComponent>(); } if (isPlayer) { PlayerBase = centerBaseTile; } else { EnemyBase = centerBaseTile; } }
protected override bool UpdateLocation(IHexGridCell location) { CreatureComponent otherCreature = location.GetComponent <CreatureComponent>(); if (!(otherCreature is null) && !(otherCreature.Creature is EnemyMovementController && IsUserControlledFunction())) { return(false); } if (Location != null) { AssertHelper.Assert(creatureComponent != null, "Missing creature component", this); bool success = Location.RemoveComponent(creatureComponent); AssertHelper.Assert(success, "Failed to remove creature component", this); } else { creatureComponent = new CreatureComponent(this); } Location = location; Location.AddComponent(creatureComponent); return(true); }