public UnitBase(GameServer _server, Player player) : base(_server, player) { EntityType = Entity.EntityType.Unit; UnitType = UnitTypes.Default; EntityToAttack = null; Speed = .01f; Range = 50; AttackDelay = 100; AttackRechargeTime = 1000; SupplyUsage = 1; RangedUnit = false; StandardAttackDamage = 1; StandardAttackElement = Entity.DamageElement.Normal; State = UnitState.Agro; allowMovement = false; _moveXCompleted = false; _moveYCompleted = false; attackTimer = new Stopwatch(); attackTimer.Reset(); attackTimer.Stop(); rechargeTimer = new Stopwatch(); rechargeTimer.Restart(); updatedMovePositionTimer = new Stopwatch(); updatedMovePositionTimer.Start(); }
public ProjectileBase(GameServer _server, Player player, Vector2f startPosition, EntityBase target, float dmg, Entity.DamageElement element, float speed = 1) : base(_server, player) { EntityType = Entity.EntityType.Projectile; Start = startPosition; Target = target; Position = Start; BoundsSize = new Vector2f(5, 5); Damage = dmg; Element = element; Speed = speed; RemoveOnNoHealth = false; }
public BuildingBase(GameServer server, Player player) : base(server, player) { IsBuilding = true; BuildTime = 1000; elapsedBuildTime = 0; buildOrder = new List<string>(); EntityType = Entity.EntityType.Building; stopwatch = new Stopwatch(); Health = 1; MaxHealth = 100; }
public override void AddConnection(NetConnection connection) { if (players.Count < MaxPlayers) { //Connected client must be a player var nPlayer = new Player { ClientId = idToGive, Team = idToGive }; nPlayer.Wood = 50; nPlayer.Supply = 10; players.Add(nPlayer); connection.Tag = nPlayer; var home =// new HomeBuilding(Server, nPlayer); BuildingBase.CreateBuilding("standardBase", Server, nPlayer); home.Team = nPlayer.Team; home.BuildTime = 0; if (TiledMap.SpawnPoints.Count > players.Count - 1) { home.Position = TiledMap.SpawnPoints[players.Count - 1]; } AddEntity(home); SendAllPlayers(); SendMap(); SendAllEntities(); SetCamera(nPlayer, home.Position); if (players.Count >= MaxPlayers) { GameStatus = StatusState.InProgress; } var memory = new MemoryStream(); var writer = new BinaryWriter(memory); writer.Write((byte) Gamemode.Signature.Handshake); writer.Write(idToGive); Server.SendGameData(memory.ToArray(), connection); } else { //Connectd client must be a spectator or something non-player type? SendAllPlayers(); SendData(map.ToBytes(), Gamemode.Signature.MapLoad); SendAllEntities(); } idToGive++; }
public static BuildingBase CreateBuilding(BuildingTypes building, GameServer server, Player player) { switch (building) { default: case BuildingTypes.Base: return CreateBuilding("base", server, player); break; case BuildingTypes.Supply: return CreateBuilding("supply", server, player); break; case BuildingTypes.GlueFactory: return CreateBuilding("gluefactory", server, player); break; } }
protected EntityBase(GameServer _server, Player player) { HotkeyString = ""; UseCount = 0; Server = _server; MyPlayer = player; Neutral = false; BoundsSize = new Vector2f(10, 10); RemoveOnNoHealth = true; EntityToUse = null; MyGameMode = null; rallyPoints = new List<Entity.RallyPoint>(); Health = 0; MaxHealth = 0; Energy = 0; EnergyRegenRate = 0; MaxEnergy = 0; Position = new Vector2f(); spells = new Dictionary<string, SpellData>(); }
public static EntityBase EntityFactory(Entity.EntityType type, GameServer server, Player ply) { switch (type) { case Entity.EntityType.Unit: break; case Entity.EntityType.Building: break; case Entity.EntityType.Worker: break; case Entity.EntityType.Resources: break; case Entity.EntityType.HomeBuilding: return new HomeBuilding(server, ply); break; case Entity.EntityType.SupplyBuilding: return new SupplyBuilding(server, ply, 12); default: break; } return null; }
public static BuildingBase CreateBuilding(string building, GameServer server, Player player) { return CreateBuildingFromXML(building, server, player); }
protected void onPlayerSurrender(Player player) { //rage quit banner popup or something }
public HomeBuilding(GameServer server, Player plr) : base(server, plr) { BuildTime = 2000; EntityType = Entity.EntityType.HomeBuilding; }
public abstract void UpdatePlayer(Player player);
protected void onPlayerElimination(Player player) { //elimation banner popup or something }
/// <summary> /// Gets players that are most suited for competition (would provide as close as possible to an even match). Both @candidates and @target need to have the TSCharacterComponent attached. /// </summary> /// <param name="candidates">the possible candidates to match against</param> /// <param name="target">the player for whom we wish to find matches</param> /// <returns>a list of character IDs in order of </returns> public static List<SkillMatchInfo> GetTopQualityMatches(IEnumerable<ICharacterInfo> candidates, ICharacterInfo target, int maxResults) { DateTime start = DateTime.UtcNow; List<SkillMatchInfo> matches = new List<SkillMatchInfo>(); try { GameInfo gi = GameInfo.DefaultGameInfo; Player targetPlayer = new Player(target.ID); double targetMu = target.Properties.GetDoubleProperty((int)TSPropertyID.RatingMean).GetValueOrDefault(); double targetSigma = target.Properties.GetDoubleProperty((int)TSPropertyID.RatingStandardDeviation).GetValueOrDefault(); Rating targetRating = new Rating(targetMu, targetSigma); Team targetTeam = new Team(targetPlayer, targetRating); int numCandidates = 0; IEnumerator<ICharacterInfo> enu = candidates.GetEnumerator(); while (enu.MoveNext()) { numCandidates++; Player player = new Player(enu.Current.ID); double mu = enu.Current.Properties.GetDoubleProperty((int)TSPropertyID.RatingMean).GetValueOrDefault(); double sigma = enu.Current.Properties.GetDoubleProperty((int)TSPropertyID.RatingStandardDeviation).GetValueOrDefault(); Rating rating = new Rating(mu, sigma); Team team = new Team(player, rating); double quality = TrueSkillCalculator.CalculateMatchQuality(gi, Teams.Concat(targetTeam, team)); matches.Add(new SkillMatchInfo(enu.Current.ID, quality)); } // Sort it matches.OrderBy(i => i.MatchQuality); // trim it, if necessary if (maxResults > 0) { if (maxResults > matches.Count) { maxResults = matches.Count; } matches = matches.GetRange(0, maxResults - 1); } DateTime end = DateTime.UtcNow; TimeSpan exeTime = end - start; int highestQuality = 0; if (matches.Count > 0) { highestQuality = (int)Math.Floor(matches[0].MatchQuality * 100); } Log.LogMsg("TrueSkill match maker tested [" + numCandidates + "] candidates for character [" + target.CharacterName + " | " + target.ID + "]. Returned [" + matches.Count + "] possible matches in [" + exeTime.TotalMilliseconds + " ms]. Best match found had a [" + highestQuality + "%] quality rating."); } catch(Exception e) { Log.LogMsg("TrueSkill match maker encountered an error when searching for match candidates. " + e.Message); } return matches; }
public void SetCamera(Player player, Vector2f pos) { var memory = new MemoryStream(); var writer = new BinaryWriter(memory); writer.Write(player.ClientId); writer.Write(pos.X); writer.Write(pos.Y); SendData(memory.ToArray(), Gamemode.Signature.SetCamera); }
public static UnitBase CreateUnit(string unit, GameServer server, Player player) { return LoadUnitFromXML(unit, server, player); }
public ResourceUnloadArea(GameServer _server, Player player) : base(_server, player) { RemoveOnNoHealth = false; EntityType = Entity.EntityType.ResourceUnloadSpot; }
public SupplyBuilding(GameServer server, Player ply, byte sAdd) : base(server, ply) { SupplyAdd = sAdd; EntityType = Entity.EntityType.SupplyBuilding; }
public static UnitBase LoadUnitFromXML(string unit, GameServer server, Player player) { var unitSetting = Settings.GetUnit(unit); if(unitSetting == null) return new UnitBase(server, player); UnitBase retUnit = null; switch (unitSetting.Type) { default: case "default": retUnit = new UnitBase(server, player); break; case "worker": retUnit = new Worker(server, player); break; } retUnit.RangedUnit = unitSetting.RangedUnit; retUnit.Range = unitSetting.Range; retUnit.Speed = unitSetting.Speed; retUnit.AttackDelay = unitSetting.AttackDelay; retUnit.AttackRechargeTime = unitSetting.AttackRechargeTime; retUnit.StandardAttackDamage = unitSetting.StandardAttackDamage; foreach (var spellXmlData in unitSetting.Spells) { var spellData = new SpellData(spellXmlData.EnergyCost, null); spellData.SpellType = SpellTypes.Normal; if(spellXmlData.IsBuildSpell) spellData.SpellType = SpellTypes.BuildingPlacement; spellData.WoodCost = spellXmlData.WoodCost; spellData.EnergyCost = spellXmlData.EnergyCost; spellData.AppleCost = spellXmlData.AppleCost; spellData.GlueCost = spellXmlData.GlueCost; retUnit.spells.Add(spellXmlData.BuildString, spellData); } retUnit.Health = unitSetting.Health; retUnit.MaxHealth = unitSetting.MaxHealth; retUnit.SupplyUsage = unitSetting.SupplyCost; retUnit.HotkeyString = unitSetting.Name; return retUnit; }
private static BuildingBase CreateBuildingFromXML(string building, GameServer server, Player player) { var buildingData = Settings.GetBuilding(building); if(buildingData == null) return new BuildingBase(server, player); BuildingBase ret = new BuildingBase(server, player); switch (buildingData.BuildingType.ToLower()) { default: ret = new BuildingBase(server, player); break; case "base": ret = new HomeBuilding(server,player); break; case "supply": ret = new SupplyBuilding(server, player, buildingData.SupplyAdd); break; case "gluefactory": ret = new GlueFactory(server, player); break; } foreach (var unitElement in buildingData.Units) { ret.spells.Add(unitElement.UnitTypeString, new SpellData(0, null) { AppleCost = unitElement.AppleCost, WoodCost = unitElement.WoodCost, CastTime = unitElement.CreationTime, GlueCost = unitElement.GlueCost, SupplyCost = unitElement.SupplyCost, SpellType = SpellTypes.UnitCreation, }); } ret.Health = buildingData.Health; ret.MaxHealth = buildingData.MaxHealth; ret.BuildTime = buildingData.BuildTime; ret.HotkeyString = buildingData.Name; return ret; }
public void ParseData(MemoryStream stream) { var reader = new BinaryReader(stream); var signature = (Gamemode.Signature) reader.ReadByte(); switch (signature) { case Gamemode.Signature.Custom: ParseCustom(stream); break; case Gamemode.Signature.Entity: { ushort id = reader.ReadUInt16(); if (entities.ContainsKey(id)) entities[id].ParseData(stream); } break; case Gamemode.Signature.MapLoad: ParseMap(stream); break; case Gamemode.Signature.TiledMapLoad: { var tiledMap = new TiledMap(); tiledMap.Load(stream); map.ApplyLevel(tiledMap); pathFinding = new SpatialAStar<PathNode, object>(map.GetPathNodeMap()); Fog = new FogOfWar(map.MapSize.X, map.MapSize.Y); for (int x = 0; x < map.MapSize.X; x++) { for (int y = 0; y < map.MapSize.Y; y++) { Fog.Grid[x, y].Blocker = map.Tiles[x, y].Solid; } } } break; case Gamemode.Signature.Handshake: ParseHandshake(stream); break; case Gamemode.Signature.EntityAdd: { ushort id = reader.ReadUInt16(); byte entityType = reader.ReadByte(); EntityBase entity = EntityBase.EntityFactory(entityType); entity.Type = (Entity.EntityType) entityType; entity.WorldEntities = entities; entity.WorldId = id; entity.MyGameMode = this; entity.LoadFromBytes(stream); AddEntity(entity, id); entity.SetTeam(reader.ReadByte()); } break; case Gamemode.Signature.EntityLoad: { ushort count = reader.ReadUInt16(); for (int i = 0; i < count; i++) { ushort entId = reader.ReadUInt16(); byte entType = reader.ReadByte(); EntityBase entAdd = EntityBase.EntityFactory(entType); entAdd.Type = (Entity.EntityType) entType; entAdd.WorldEntities = entities; entAdd.LoadFromBytes(stream); entAdd.WorldId = entId; entAdd.MyGameMode = this; AddEntity(entAdd, entId); entAdd.SetTeam(reader.ReadByte()); } } break; case Gamemode.Signature.PlayerData: { byte playerId = reader.ReadByte(); if (players.ContainsKey(playerId)) { players[playerId].Load(stream); } } break; case Gamemode.Signature.PlayersLoad: { byte count = reader.ReadByte(); for (int i = 0; i < count; i++) { var playerAdd = new Player(); playerAdd.Load(stream); if (players.ContainsKey(playerAdd.ClientId) == false) { players.Add(playerAdd.ClientId, playerAdd); } } } break; case Gamemode.Signature.RemoveEntity: { ushort id = reader.ReadUInt16(); if (entities.ContainsKey(id)) { entities[id].OnDeath(); entities.Remove(id); } } break; case Gamemode.Signature.GroupMovement: { float x = reader.ReadSingle(); float y = reader.ReadSingle(); bool reset = reader.ReadBoolean(); bool attack = reader.ReadBoolean(); byte count = reader.ReadByte(); for (int i = 0; i < count; i++) { ushort id = reader.ReadUInt16(); if (!entities.ContainsKey(id)) continue; if (reset) entities[id].ClearRally(); Vector2f startPos = entities[id].Position; if (!reset && entities[id].rallyPoints.Count > 0) { startPos = new Vector2f(entities[id].rallyPoints[entities[id].rallyPoints.Count - 1].X, entities[id].rallyPoints[entities[id].rallyPoints.Count - 1].Y); } PathFindReturn path = PathFindNodes(startPos.X, startPos.Y, x, y); if (path.List == null) continue; foreach (PathNode pathNode in path.List) { if (pathNode == path.List.First.Value) continue; var pos = new Vector2f(pathNode.X*path.MapSize.X + (path.MapSize.X/2), pathNode.Y*path.MapSize.Y + (path.MapSize.Y/2)); entities[id].Move(pos.X, pos.Y, attack); } } } break; case Gamemode.Signature.SetCamera: { SetCamera(reader.ReadByte(), new Vector2f(reader.ReadSingle(), reader.ReadSingle())); } break; case Gamemode.Signature.UpdatePosition: { ushort unitId = reader.ReadUInt16(); float posX = reader.ReadSingle(); float posY = reader.ReadSingle(); if (entities.ContainsKey(unitId)) { entities[unitId].Position = new Vector2f(posX, posY); } } break; } }
public override void UpdatePlayer(Player player) { var memory = new MemoryStream(); var writer = new BinaryWriter(memory); writer.Write(player.ClientId); writer.Write(player.ToBytes()); SendData(memory.ToArray(), Gamemode.Signature.PlayerData); memory.Close(); writer.Close(); }
public GameState(Player currentPlayer, Player[,] board) { CurrentPlayer = currentPlayer; Board = board; }
public static UnitBase CreateUnit(UnitTypes unit, GameServer server, Player player) { UnitBase retUnit = null; switch (unit) { default: case UnitTypes.Default: retUnit = LoadUnitFromXML("default", server, player); break; case UnitTypes.Worker: retUnit = LoadUnitFromXML("worker", server, player); break; case UnitTypes.Unicorn: retUnit = LoadUnitFromXML("unicorn", server, player); break; } return retUnit; }