public SendUnit(ExteelUser user, UnitRecord unit) { HighPriority = true; _unit = unit; _user = user; }
protected Unit(GameInstance instance, UnitRecord unitRecord) { GameInstance = instance; Id = unitRecord.Id; Team = unitRecord.User?.Team ?? 0; Name = unitRecord.Name; Head = new Part(unitRecord.Head, this); Chest = new Part(unitRecord.Chest, this); Arms = new Arms(unitRecord.Arms, this); Legs = new Part(unitRecord.Legs, this); Booster = new Part(unitRecord.Backpack, this); var left = CreateWeapon(unitRecord.WeaponSet1Left, ArmIndex.Left, WeaponSetIndex.Primary); var right = unitRecord.WeaponSet1Right != null ? CreateWeapon(unitRecord.WeaponSet1Right, ArmIndex.Right, WeaponSetIndex.Primary) : new NullWeapon(this, ArmIndex.Right, WeaponSetIndex.Primary); WeaponSetPrimary = (left, right); left = CreateWeapon(unitRecord.WeaponSet2Left, ArmIndex.Left, WeaponSetIndex.Secondary); right = unitRecord.WeaponSet2Right != null ? CreateWeapon(unitRecord.WeaponSet2Right, ArmIndex.Right, WeaponSetIndex.Secondary) : new NullWeapon(this, ArmIndex.Right, WeaponSetIndex.Secondary); WeaponSetSecondary = (left, right); }
private void UnitUpdated(object sender, UnitRecord unitRecord) { if (unitRecord.Id == _unitRecord.Id) { _unitRecord = unitRecord; } }
public void Add(UnitRecord unitRecord) { // referential integrity: //GetStackById(unitRecord.StackId.Value); _gameConfigCache.GetUnitConfigById(unitRecord.UnitTypeId.Value); Units.Add(unitRecord); }
internal void EndTurn() { var movementPoints = _gameConfigCache.GetUnitConfigById(_unitRecord.UnitTypeId.Value).MovementPoints; var updatedUnit = new UnitRecord(_unitRecord, new MovementPoints(movementPoints)); _gameDataRepository.Update(updatedUnit); }
public void Update(UnitRecord unitRecord) { // referential integrity: //GetStackById(unitRecord.StackId.Value); _gameConfigCache.GetUnitConfigById(unitRecord.UnitTypeId.Value); Units.Update(unitRecord); UnitUpdated?.Invoke(this, unitRecord); }
public Unit(int id) { _gameConfigCache = CallContext <GameConfigCache> .GetData("GameConfigCache"); _gameDataRepository = CallContext <GameDataRepository> .GetData("GameDataRepository"); _unitRecord = _gameDataRepository.GetUnitById(id); _gameDataRepository.UnitUpdated += UnitUpdated; }
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); }
/// <summary> /// Tries to respawn a unit /// </summary> /// <param name="desiredUnit">The unit they wish to spawn</param> /// <param name="owner">Owner of the unit</param> /// <returns></returns> public bool TryRegain(UnitRecord desiredUnit, GameSession owner) { // TODO: Check for spawn timers, etc // TODO: Handle multiple units per user if (!BeforeRegain(desiredUnit, owner)) { return(false); } SpawnUnit(desiredUnit, owner); return(true); }
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 void initialize(BattleBuilding from, BattleBuilding to, int unitCount) { _attachedToBuilding = false; setOwnerId(from.ownerId); _level = from.level; _info = engine.configuration.unitRecords.GetBy(from.info.Levels[from.level].UnitId, from.info.Race); _infoLevel = _info.Levels[_level]; _move.moveTo(to.transform); transform.setFrom(from.transform); _unitHP = engine.players.getPlayer(from.ownerId).modifier.calculate(ModifierType.UNITS_HP, _infoLevel.Hp, _info.Id); _hp = _unitHP * unitCount; units.setCount(getUnits()); }
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 void Unit_tests() { var unitRecord = new UnitRecord(0, 1); _repo.Add(unitRecord); var id = unitRecord.Id; unitRecord = _repo.GetUnitById(id); var units = _repo.GetUnitsByStackId(1); Assert.AreEqual(id, unitRecord.Id); Assert.AreEqual(1, unitRecord.StackId.Value); Assert.AreEqual(0, unitRecord.UnitTypeId.Value); Assert.AreEqual(1.0f, unitRecord.MovementPoints.Value); Assert.AreEqual(1, units.Count); Assert.AreEqual(1, units[0].Id); units = _repo.GetUnitsByFactionId(1); Assert.AreEqual(1, units.Count); Assert.AreEqual(1, units[0].Id); var updatedUnit = new UnitRecord(unitRecord, new StackId(2), new MovementPoints(1.0f)); _repo.Update(updatedUnit); unitRecord = _repo.GetUnitById(id); Assert.AreEqual(2, unitRecord.StackId.Value); Assert.AreEqual(0, unitRecord.UnitTypeId.Value); Assert.AreEqual(1.0f, unitRecord.MovementPoints.Value); updatedUnit = new UnitRecord(unitRecord, new StackId(1)); _repo.Update(updatedUnit); unitRecord = _repo.GetUnitById(id); Assert.AreEqual(1, unitRecord.StackId.Value); Assert.AreEqual(0, unitRecord.UnitTypeId.Value); Assert.AreEqual(1.0f, unitRecord.MovementPoints.Value); updatedUnit = new UnitRecord(unitRecord, new MovementPoints(3.0f)); _repo.Update(updatedUnit); unitRecord = _repo.GetUnitById(id); Assert.AreEqual(1, unitRecord.StackId.Value); Assert.AreEqual(0, unitRecord.UnitTypeId.Value); Assert.AreEqual(3.0f, unitRecord.MovementPoints.Value); }
/// <summary> /// Spawns a new unit into the game /// </summary> /// <param name="unit"></param> /// <param name="user"></param> protected void SpawnUnit(UnitRecord unit, GameSession owner) { // Create the unit var spawnedUnit = new UserUnit(this, unit, owner); // Add to dictionary _units.TryAdd(unit.Id, spawnedUnit); // Set the current unit to the user owner.CurrentUnit = spawnedUnit; // Set team spawnedUnit.Team = owner.User.Team; // Set state spawnedUnit.State = UnitState.Spawned; // Calculate stats spawnedUnit.CalculateStats(); // Set hp to max - auto clamps to max hp spawnedUnit.CurrentHealth = 9999; // Set unit Location spawnedUnit.WorldPosition = GetSpawnForUnit(spawnedUnit); // Notify //RoomInstance.MulticastPacket(new CodeList(spawnedUnit.Skills)); // Send unit info RoomInstance.MulticastPacketWithSession(session => new UnitInfo(spawnedUnit, session)); // Send spawn command RoomInstance.MulticastPacket(new SpawnUnit(spawnedUnit)); // Send status? RoomInstance.MulticastPacket(new StatusChanged(spawnedUnit, true, false, true)); // Call hook AfterUnitSpawned(spawnedUnit, owner); $"Unit Spawned ${unit} - ${unit.Id} - ${owner.User.Team}".Info(); }
/// <summary> /// Spawns a new unit into the game /// </summary> /// <param name="unit"></param> /// <param name="user"></param> protected void SpawnUnit(UnitRecord unit, GameSession owner) { // Create the unit var spawnedUnit = new UserUnit(this, unit, owner); // Add to dictionary _units.TryAdd(unit.Id, spawnedUnit); // Set the current unit to the user owner.CurrentUnit = spawnedUnit; // Set team spawnedUnit.Team = owner.User.Team; // Calculate stats spawnedUnit.CalculateStats(); // Set hp to max - auto clamps to max hp spawnedUnit.CurrentHealth = 9999; // Set unit Location // TODO: Spawn maps? spawnedUnit.WorldPosition = new Vector3(SpawnLocation.X, SpawnLocation.Y, SpawnLocation.Z); // Notify RoomInstance.MulticastPacket(new CodeList(spawnedUnit.Skills)); // Send unit info RoomInstance.MulticastPacket(new UnitInfo(spawnedUnit)); // Send spawn command RoomInstance.MulticastPacket(new SpawnUnit(spawnedUnit)); // Send status? RoomInstance.MulticastPacket(new StatusChanged(spawnedUnit, true, true, true)); // Call hook AfterUnitSpawned(spawnedUnit, owner); }
protected Unit(GameInstance instance, UnitRecord unitRecord) { GameInstance = instance; Id = unitRecord.Id; Team = unitRecord.User?.Team ?? 0; Name = unitRecord.Name; Head = new Part(unitRecord.Head, this); Chest = new Part(unitRecord.Chest, this); Arms = new Arms(unitRecord.Arms, this); Legs = new Part(unitRecord.Legs, this); Booster = new Part(unitRecord.Backpack, this); _skills = new Skill[] { unitRecord.Skill1 != null?CreateSkill(unitRecord.Skill1) : null, unitRecord.Skill2 != null?CreateSkill(unitRecord.Skill2) : null, unitRecord.Skill3 != null?CreateSkill(unitRecord.Skill3) : null, unitRecord.Skill4 != null?CreateSkill(unitRecord.Skill4) : null }; // Add to master list // GameInstance.AddSkills(Skills.Where(s => s != null)); var left = CreateWeapon(unitRecord.WeaponSet1Left, ArmIndex.Left, WeaponSetIndex.Primary); var right = unitRecord.WeaponSet1Right != null ? CreateWeapon(unitRecord.WeaponSet1Right, ArmIndex.Right, WeaponSetIndex.Primary) : new NullWeapon(this, ArmIndex.Right, WeaponSetIndex.Primary); WeaponSetPrimary = (left, right); left = CreateWeapon(unitRecord.WeaponSet2Left, ArmIndex.Left, WeaponSetIndex.Secondary); right = unitRecord.WeaponSet2Right != null ? CreateWeapon(unitRecord.WeaponSet2Right, ArmIndex.Right, WeaponSetIndex.Secondary) : new NullWeapon(this, ArmIndex.Right, WeaponSetIndex.Secondary); WeaponSetSecondary = (left, right); }
/// <summary> /// Users can always respawn /// </summary> /// <param name="desiredUnit"></param> /// <param name="owner"></param> /// <returns></returns> protected override bool BeforeRegain(UnitRecord desiredUnit, GameSession owner) { return(true); }
public UnitInfo(ExteelUser user, UnitRecord unit) { _unit = unit; _user = user; }
public NpcUnit(GameInstance instance, UnitRecord unitRecord) : base(instance, unitRecord) { }
public SendPalette(UnitRecord unit) { HighPriority = true; _unit = unit; }
public RegainResult(UnitRecord unit, bool result) { _unit = unit; _result = result; }
/// <summary> /// Spawns an npc at a position /// </summary> /// <param name="pos">Where to spawn the npc</param> /// <param name="npcType">The type of npc</param> /// <param name="scale">How large it is</param> /// <param name="team">The team the npc is on</param> /// <returns>The unit that was created</returns> public Unit SpawnNpc(Vector3 pos, uint npcType = 1, float scale = 1.0f, uint team = 1000) { var unit = new UnitRecord { Id = nextNpcId++, Name = "NPC_Puppet_Guard", Head = new PartRecord { Id = -1, TemplateId = 1030603, Parameters = 1, Color = Color.Gray, Type = 1 }, Chest = new PartRecord { Id = -1, TemplateId = 2030601, Parameters = 1, Color = Color.Gray, Type = 2 }, Arms = new PartRecord { Id = -1, TemplateId = 3030601, Parameters = 1, Color = Color.Gray, Type = 3 }, Legs = new PartRecord { Id = -1, TemplateId = 4030601, Parameters = 1, Color = Color.Gray, Type = 4 }, Backpack = new PartRecord { Id = -1, TemplateId = 5030601, Parameters = 1, Color = Color.Gray, Type = 5 }, WeaponSet1Left = new PartRecord { Id = -1, TemplateId = 7010101, Parameters = 1, Color = Color.Gray, Type = 7 }, WeaponSet1Right = new PartRecord { Id = -1, TemplateId = 7010101, Parameters = 1, Color = Color.Gray, Type = 7 }, WeaponSet2Left = new PartRecord { Id = -1, TemplateId = 7010101, Parameters = 4, Color = Color.Gray, Type = 7 }, WeaponSet2Right = new PartRecord { Id = -1, TemplateId = 7010101, Parameters = 1, Color = Color.Gray, Type = 7 } }; var spawnedUnit = new NpcUnit(this, unit); // Add to dictionary _units[unit.Id] = spawnedUnit; // Set team spawnedUnit.Team = team; // Calculate stats spawnedUnit.CalculateStats(); // Set hp to max - auto clamps to max hp spawnedUnit.CurrentHealth = 9999; // Set state spawnedUnit.State = UnitState.Spawned; // Set unit Location // TODO: Spawn maps? spawnedUnit.WorldPosition = new Vector3(pos.X, pos.Y, pos.Z); // Send unit info RoomInstance.MulticastPacket(new NpcInfo(spawnedUnit, npcType, scale)); // Send spawn command RoomInstance.MulticastPacket(new SpawnUnit(spawnedUnit)); // Send status? RoomInstance.MulticastPacket(new StatusChanged(spawnedUnit, true, false, true)); return(spawnedUnit); }
/// <summary> /// Called before respawning a unit. Return false to prevent spawning. /// </summary> /// <param name="desiredUnit"></param> /// <param name="owner"></param> /// <returns></returns> protected abstract bool BeforeRegain(UnitRecord desiredUnit, GameSession owner);
public UserUnit(GameInstance instance, UnitRecord unitRecord, GameSession owner) : base(instance, unitRecord) { Owner = owner; }