public void Add(StackRecord stackRecord) { // referential integrity: //GetFactionById(stackRecord.FactionId.Value); Stacks.Add(stackRecord); }
private void DoPatrolAction() { var updatedStack = new StackRecord(_stackRecord, _stackRecord.LocationHex, new Status(UnitStatus.Patrol), new HaveOrdersBeenGivenThisTurn(true)); _gameDataRepository.Update(updatedStack); Units.DoPatrolAction(); }
internal void MoveTo(PointI locationToMoveTo) { var world = CallContext <World> .GetData("GameWorld"); var cellToMoveTo = world.OverlandMap.CellGrid.GetCell(locationToMoveTo); var movementCost = Helpers.MovementCosts.GetCostToMoveInto(cellToMoveTo, MovementTypes, MovementPoints); foreach (var unit in Units) { var updatedStack = new StackRecord(_stackRecord, new LocationHex(locationToMoveTo)); _gameDataRepository.Update(updatedStack); unit.SetSeenCells(LocationHex); //var newMovementPoints = unit.MovementPoints - movementCost.CostToMoveInto; //var unitRecord = gameDataRepository.GetUnitById(unit.Id); //var updatedUnit = new UnitRecord(updatedUnit, updatedUnit.Stackid, newMovementPoints); //gameDataRepository.Update(updatedUnit); //if (unit.MovementPoints <= 0.0f) //{ // unit.MovementPoints = 0.0f; // updatedStack = new StackRecord(_stackRecord, _stackRecord.LocationHex, _stackRecord.Status, true); // gameDataRepository.Update(updatedStack); //} } }
private void StackUpdated(object sender, StackRecord stackRecord) { if (stackRecord.Id == _stackRecord.Id) { _stackRecord = stackRecord; } }
internal void BeginTurn() { var ordersGiven = Status == UnitStatus.Fortify || Status == UnitStatus.Patrol; // TODO: de-hardcode these, a persistent flag? var updatedStack = new StackRecord(_stackRecord, _stackRecord.LocationHex, _stackRecord.Status, new HaveOrdersBeenGivenThisTurn(ordersGiven)); _gameDataRepository.Update(updatedStack); }
public void SetStatusToNone() { var updatedStack = new StackRecord(_stackRecord, _stackRecord.LocationHex, new Status(UnitStatus.None), new HaveOrdersBeenGivenThisTurn(false)); _gameDataRepository.Update(updatedStack); Units.SetStatusToNone(); }
public void Update(StackRecord stackRecord) { // referential integrity: //GetFactionById(stackRecord.FactionId.Value); Stacks.Update(stackRecord); StackUpdated?.Invoke(this, stackRecord); }
internal void SetStatusToNone() { var stackRecord = _gameDataRepository.GetStackById(_unitRecord.StackId.Value); var updatedStack = new StackRecord(stackRecord, new Status(UnitStatus.None)); _gameDataRepository.Update(updatedStack); //SetSeenCells(stackRecord.LocationHex.Value); }
internal void DoPatrolAction() { var stackRecord = _gameDataRepository.GetStackById(_unitRecord.StackId.Value); var updatedStack = new StackRecord(stackRecord, new Status(UnitStatus.Patrol)); _gameDataRepository.Update(updatedStack); _unitRecord = new UnitRecord(_unitRecord, new MovementPoints(0.0f)); _gameDataRepository.Update(_unitRecord); //SetSeenCells(stackRecord.LocationHex.Value); }
internal void DoFortifyAction() { // TODO: increment defense by 1 var stackRecord = _gameDataRepository.GetStackById(_unitRecord.StackId.Value); var updatedStack = new StackRecord(stackRecord, new Status(UnitStatus.Fortify)); _gameDataRepository.Update(updatedStack); _unitRecord = new UnitRecord(_unitRecord, new MovementPoints(0.0f)); _gameDataRepository.Update(_unitRecord); //SetSeenCells(stackRecord.LocationHex.Value); }
public override void Execute() { var payload = ((PointI position, int unitId, Stacks stacks))Payload; var stackRecord = new StackRecord(1, payload.position); var unitRecord = new UnitRecord(payload.unitId, stackRecord.Id); var gameDataRepository = CallContext <GameDataRepository> .GetData("GameDataRepository"); gameDataRepository.Add(stackRecord); gameDataRepository.Add(unitRecord); //var stacks = payload.stacks; //stacks.Add(stackRecord); }
public static World MakeWorld() { var gameConfigRepository = CallContext <GameConfigRepository> .GetData("GameConfigRepository"); var gameDataRepository = CallContext <GameDataRepository> .GetData("GameDataRepository"); var factionRecord = new FactionRecord(1, 0, 0); // barbarians gameDataRepository.Add(factionRecord); var stackRecord1 = new StackRecord(factionRecord.Id, new PointI(12, 9)); gameDataRepository.Add(stackRecord1); var stackRecord2 = new StackRecord(factionRecord.Id, new PointI(15, 7)); gameDataRepository.Add(stackRecord2); var stackRecord3 = new StackRecord(factionRecord.Id, new PointI(12, 9)); gameDataRepository.Add(stackRecord3); var unitRecord1 = new UnitRecord(100, stackRecord1.Id); // test dude gameDataRepository.Add(unitRecord1); var unitRecord2 = new UnitRecord(1, stackRecord2.Id); // barbarian settlers gameDataRepository.Add(unitRecord2); var unitRecord3 = new UnitRecord(2, stackRecord3.Id); // barbarian spearmen gameDataRepository.Add(unitRecord3); var faction = new Faction(factionRecord.Id); var world = new World(Constants.WORLD_MAP_COLUMNS, Constants.WORLD_MAP_ROWS, faction); CallContext <World> .SetData("GameWorld", world); world.AddSettlement(new PointI(12, 9), 1); var stack1 = new Stack(stackRecord1.Id); world.AddUnit(stack1); var stack2 = new Stack(stackRecord2.Id); world.AddUnit(stack2); var stack3 = new Stack(stackRecord3.Id); world.AddUnit(stack3); return(world); }
public Stack(int stackId) { _gameConfigCache = CallContext <GameConfigCache> .GetData("GameConfigCache"); _gameDataRepository = CallContext <GameDataRepository> .GetData("GameDataRepository"); _stackRecord = _gameDataRepository.GetStackById(stackId); var unitRecords = _gameDataRepository.GetUnitsByStackId(stackId); Units = new Units(); foreach (var unitRecord in unitRecords) { Units.Add(new Unit(unitRecord.Id)); } _gameDataRepository.StackUpdated += StackUpdated; }
public BlockProfileRecord(long Count = default, long Cycles = default, StackRecord StackRecord = default) { this.Count = Count; this.Cycles = Cycles; this.m_StackRecordRef = new ptr <StackRecord>(StackRecord); }
public void Stack_tests() { var stackRecord = new StackRecord(1, new PointI(12, 9)); _repo.Add(stackRecord); var id = stackRecord.Id; stackRecord = _repo.GetStackById(id); var stacks = _repo.GetStacksByFactionId(1); Assert.AreEqual(id, stackRecord.Id); Assert.AreEqual(1, stackRecord.FactionId.Value); Assert.AreEqual(UnitStatus.None, stackRecord.Status.Value); Assert.AreEqual(false, stackRecord.HaveOrdersBeenGivenThisTurn.Value); Assert.AreEqual(3, stacks.Count); Assert.AreEqual(1, stacks[0].Id); Assert.AreEqual(2, stacks[1].Id); stacks = _repo.GetStacksByLocationHex(new PointI(12, 9)); Assert.AreEqual(1, stacks.Count); Assert.AreEqual(3, stacks[0].Id); stacks = _repo.GetStacksByOrdersNotBeenGivenThisTurnAndFactionId(1); Assert.AreEqual(3, stacks.Count); Assert.AreEqual(1, stacks[0].Id); Assert.AreEqual(2, stacks[1].Id); Assert.AreEqual(3, stacks[2].Id); var updatedStack = new StackRecord(stackRecord, stackRecord.LocationHex, new Status(UnitStatus.Patrol), new HaveOrdersBeenGivenThisTurn(true)); _repo.Update(updatedStack); stackRecord = _repo.GetStackById(id); Assert.AreEqual(1, stackRecord.FactionId.Value); Assert.AreEqual(new PointI(12, 9), stackRecord.LocationHex.Value); Assert.AreEqual(UnitStatus.Patrol, stackRecord.Status.Value); Assert.AreEqual(true, stackRecord.HaveOrdersBeenGivenThisTurn.Value); updatedStack = new StackRecord(stackRecord, new LocationHex(new PointI(10, 10))); _repo.Update(updatedStack); stackRecord = _repo.GetStackById(id); Assert.AreEqual(1, stackRecord.FactionId.Value); Assert.AreEqual(new PointI(10, 10), stackRecord.LocationHex.Value); Assert.AreEqual(UnitStatus.Patrol, stackRecord.Status.Value); Assert.AreEqual(true, stackRecord.HaveOrdersBeenGivenThisTurn.Value); updatedStack = new StackRecord(stackRecord, new Status(UnitStatus.Explore)); _repo.Update(updatedStack); stackRecord = _repo.GetStackById(id); Assert.AreEqual(1, stackRecord.FactionId.Value); Assert.AreEqual(new PointI(10, 10), stackRecord.LocationHex.Value); Assert.AreEqual(UnitStatus.Explore, stackRecord.Status.Value); Assert.AreEqual(true, stackRecord.HaveOrdersBeenGivenThisTurn.Value); updatedStack = new StackRecord(stackRecord, new HaveOrdersBeenGivenThisTurn(false)); _repo.Update(updatedStack); stackRecord = _repo.GetStackById(id); Assert.AreEqual(1, stackRecord.FactionId.Value); Assert.AreEqual(new PointI(10, 10), stackRecord.LocationHex.Value); Assert.AreEqual(UnitStatus.Explore, stackRecord.Status.Value); Assert.AreEqual(false, stackRecord.HaveOrdersBeenGivenThisTurn.Value); }