/// <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); }