public bool Process() { if (!MapLogic.Instance.IsLoaded) { return(false); } if (X < 0 || X >= MapLogic.Instance.Width || Y < 0 || Y >= MapLogic.Instance.Height) { return(false); } MapNode node = MapLogic.Instance.Nodes[X, Y]; foreach (MapObject mobj in node.Objects) { // check object type. if (mobj.GetObjectType() != MapObjectType.Obstacle) { continue; } MapObstacle ob = (MapObstacle)mobj; ob.SetDead(false); } return(true); }
public bool Process() { if (!MapLogic.Instance.IsLoaded) { return(false); } if (X < 0 || X >= MapLogic.Instance.Width || Y < 0 || Y >= MapLogic.Instance.Height) { return(false); } MapNode node = MapLogic.Instance.Nodes[X, Y]; for (int i = 0; i < node.Objects.Count; i++) { // check object type. if (node.Objects[i].GetObjectType() != MapObjectType.Obstacle) { continue; } MapObstacle ob = (MapObstacle)node.Objects[i]; ob.SetDead(false); } return(true); }
public void Deserialize(IDataReader reader) { Obstacles = new MapObstacle[reader.ReadShort()]; for (var i = 0; i < Obstacles.Length; i++) { (Obstacles[i] = new MapObstacle()).Deserialize(reader); } }
public override void Serialize(IDataWriter writer) { writer.WriteShort(((short)(m_houses.Count))); int housesIndex; for (housesIndex = 0; (housesIndex < m_houses.Count); housesIndex = (housesIndex + 1)) { HouseInformations objectToSend = m_houses[housesIndex]; writer.WriteUShort(((ushort)(objectToSend.TypeID))); objectToSend.Serialize(writer); } writer.WriteShort(((short)(m_actors.Count))); int actorsIndex; for (actorsIndex = 0; (actorsIndex < m_actors.Count); actorsIndex = (actorsIndex + 1)) { GameRolePlayActorInformations objectToSend = m_actors[actorsIndex]; writer.WriteUShort(((ushort)(objectToSend.TypeID))); objectToSend.Serialize(writer); } writer.WriteShort(((short)(m_interactiveElements.Count))); int interactiveElementsIndex; for (interactiveElementsIndex = 0; (interactiveElementsIndex < m_interactiveElements.Count); interactiveElementsIndex = (interactiveElementsIndex + 1)) { InteractiveElement objectToSend = m_interactiveElements[interactiveElementsIndex]; writer.WriteUShort(((ushort)(objectToSend.TypeID))); objectToSend.Serialize(writer); } writer.WriteShort(((short)(m_statedElements.Count))); int statedElementsIndex; for (statedElementsIndex = 0; (statedElementsIndex < m_statedElements.Count); statedElementsIndex = (statedElementsIndex + 1)) { StatedElement objectToSend = m_statedElements[statedElementsIndex]; objectToSend.Serialize(writer); } writer.WriteShort(((short)(m_obstacles.Count))); int obstaclesIndex; for (obstaclesIndex = 0; (obstaclesIndex < m_obstacles.Count); obstaclesIndex = (obstaclesIndex + 1)) { MapObstacle objectToSend = m_obstacles[obstaclesIndex]; objectToSend.Serialize(writer); } writer.WriteShort(((short)(m_fights.Count))); int fightsIndex; for (fightsIndex = 0; (fightsIndex < m_fights.Count); fightsIndex = (fightsIndex + 1)) { FightCommonInformations objectToSend = m_fights[fightsIndex]; objectToSend.Serialize(writer); } m_fightStartPositions.Serialize(writer); writer.WriteVarShort(m_subAreaId); writer.WriteInt(m_mapId); writer.WriteBoolean(m_hasAggressiveMonsters); }
public override void Deserialize(IDataReader reader) { mapId = reader.ReadInt(); if (mapId < 0) { throw new Exception("Forbidden value on mapId = " + mapId + ", it doesn't respect the following condition : mapId < 0"); } subareaId = reader.ReadShort(); if (subareaId < 0) { throw new Exception("Forbidden value on subareaId = " + subareaId + ", it doesn't respect the following condition : subareaId < 0"); } var limit = reader.ReadUShort(); houses = new HouseInformations[limit]; for (int i = 0; i < limit; i++) { houses[i] = (HouseInformations)ProtocolTypeManager.GetInstance(reader.ReadUShort()); houses[i].Deserialize(reader); } limit = reader.ReadUShort(); actors = new GameRolePlayActorInformations[limit]; for (int i = 0; i < limit; i++) { actors[i] = (GameRolePlayActorInformations)ProtocolTypeManager.GetInstance(reader.ReadUShort()); actors[i].Deserialize(reader); } limit = reader.ReadUShort(); interactiveElements = new InteractiveElement[limit]; for (int i = 0; i < limit; i++) { interactiveElements[i] = new InteractiveElement(); interactiveElements[i].Deserialize(reader); } limit = reader.ReadUShort(); statedElements = new StatedElement[limit]; for (int i = 0; i < limit; i++) { statedElements[i] = new StatedElement(); statedElements[i].Deserialize(reader); } limit = reader.ReadUShort(); obstacles = new MapObstacle[limit]; for (int i = 0; i < limit; i++) { obstacles[i] = new MapObstacle(); obstacles[i].Deserialize(reader); } limit = reader.ReadUShort(); fights = new FightCommonInformations[limit]; for (int i = 0; i < limit; i++) { fights[i] = new FightCommonInformations(); fights[i].Deserialize(reader); } }
public override void Deserialize(IDataReader reader) { uint num = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num; ++index) { MapObstacle mapObstacle = new MapObstacle(); mapObstacle.Deserialize(reader); this.obstacles.Add(mapObstacle); } }
public override void Serialize(IDataWriter writer) { writer.WriteShort(((short)(m_obstacles.Count))); int obstaclesIndex; for (obstaclesIndex = 0; (obstaclesIndex < m_obstacles.Count); obstaclesIndex = (obstaclesIndex + 1)) { MapObstacle objectToSend = m_obstacles[obstaclesIndex]; objectToSend.Serialize(writer); } }
public override void Deserialize(IDataReader reader) { var limit = reader.ReadUShort(); obstacles = new MapObstacle[limit]; for (int i = 0; i < limit; i++) { obstacles[i] = new MapObstacle(); obstacles[i].Deserialize(reader); } }
public override void Deserialize(ICustomDataInput reader) { var countObstacles = reader.ReadShort(); Obstacles = new List <MapObstacle>(); for (short i = 0; i < countObstacles; i++) { MapObstacle type = new MapObstacle(); type.Deserialize(reader); Obstacles.Add(type); } }
public override void Deserialize(IDataReader reader) { var obstaclesCount = reader.ReadUShort(); Obstacles = new List <MapObstacle>(); for (var obstaclesIndex = 0; obstaclesIndex < obstaclesCount; obstaclesIndex++) { var objectToAdd = new MapObstacle(); objectToAdd.Deserialize(reader); Obstacles.Add(objectToAdd); } }
public override void Deserialize(IDataReader reader) { int obstaclesCount = reader.ReadUShort(); int obstaclesIndex; m_obstacles = new System.Collections.Generic.List <MapObstacle>(); for (obstaclesIndex = 0; (obstaclesIndex < obstaclesCount); obstaclesIndex = (obstaclesIndex + 1)) { MapObstacle objectToAdd = new MapObstacle(); objectToAdd.Deserialize(reader); m_obstacles.Add(objectToAdd); } }
// Add the obstacle information to the visibleEntities list public void AddObstacleInfo(MapObstacle obs) { if (visibleEntities == null) { visibleEntities = new List <ViewInfoEntity>(); } ViewInfoEntity vie = new ViewInfoEntity(); vie.entityType = (obs.isBreakable ? ViewInfoEntityType.DestructableObject : ViewInfoEntityType.NonDestructableObject); vie.position = obs.transform.position; vie.forward = obs.transform.forward; visibleEntities.Add(vie); }
public void Deserialize(IDataReader reader) { SubAreaId = (UInt16)reader.ReadVarShort(); MapId = reader.ReadDouble(); Houses = new HouseInformations[reader.ReadShort()]; for (var i = 0; i < Houses.Length; i++) { (Houses[i] = new HouseInformations()).Deserialize(reader); } Actors = new GameRolePlayActorInformations[reader.ReadShort()]; for (var i = 0; i < Actors.Length; i++) { (Actors[i] = new GameRolePlayActorInformations()).Deserialize(reader); } InteractiveElements = new InteractiveElement[reader.ReadShort()]; for (var i = 0; i < InteractiveElements.Length; i++) { (InteractiveElements[i] = new InteractiveElement()).Deserialize(reader); } StatedElements = new StatedElement[reader.ReadShort()]; for (var i = 0; i < StatedElements.Length; i++) { (StatedElements[i] = new StatedElement()).Deserialize(reader); } Obstacles = new MapObstacle[reader.ReadShort()]; for (var i = 0; i < Obstacles.Length; i++) { (Obstacles[i] = new MapObstacle()).Deserialize(reader); } Fights = new FightCommonInformations[reader.ReadShort()]; for (var i = 0; i < Fights.Length; i++) { (Fights[i] = new FightCommonInformations()).Deserialize(reader); } HasAggressiveMonsters = reader.ReadBoolean(); FightStartPositions = new FightStartingPositions(); FightStartPositions.Deserialize(reader); }
public override void Deserialize(IDataReader reader) { SubAreaId = reader.ReadVarUhShort(); MapId = (uint)reader.ReadDouble(); var HousesCount = reader.ReadShort(); Houses = new List <HouseInformations>(); for (var i = 0; i < HousesCount; i++) { HouseInformations objectToAdd = ProtocolTypeManager.GetInstance(reader.ReadUShort()); objectToAdd.Deserialize(reader); Houses.Add(objectToAdd); } var ActorsCount = reader.ReadShort(); Actors = new List <GameRolePlayActorInformations>(); for (var i = 0; i < ActorsCount; i++) { GameRolePlayActorInformations objectToAdd = ProtocolTypeManager.GetInstance(reader.ReadUShort()); objectToAdd.Deserialize(reader); Actors.Add(objectToAdd); } var InteractiveElementsCount = reader.ReadShort(); InteractiveElements = new List <InteractiveElement>(); for (var i = 0; i < InteractiveElementsCount; i++) { InteractiveElement objectToAdd = ProtocolTypeManager.GetInstance(reader.ReadUShort()); objectToAdd.Deserialize(reader); InteractiveElements.Add(objectToAdd); } var StatedElementsCount = reader.ReadShort(); StatedElements = new List <StatedElement>(); for (var i = 0; i < StatedElementsCount; i++) { var objectToAdd = new StatedElement(); objectToAdd.Deserialize(reader); StatedElements.Add(objectToAdd); } var ObstaclesCount = reader.ReadShort(); Obstacles = new List <MapObstacle>(); for (var i = 0; i < ObstaclesCount; i++) { var objectToAdd = new MapObstacle(); objectToAdd.Deserialize(reader); Obstacles.Add(objectToAdd); } var FightsCount = reader.ReadShort(); Fights = new List <FightCommonInformations>(); for (var i = 0; i < FightsCount; i++) { var objectToAdd = new FightCommonInformations(); objectToAdd.Deserialize(reader); Fights.Add(objectToAdd); } HasAggressiveMonsters = reader.ReadBoolean(); FightStartPositions = new FightStartingPositions(); FightStartPositions.Deserialize(reader); }
public static object GetInstance(uint typeId) { object obj = null; switch (typeId) { case 11: obj = new Types.Version(); break; case 25: obj = new GameServerInformations(); break; case 55: obj = new EntityLook(); break; case 54: obj = new SubEntity(); break; case 110: obj = new CharacterMinimalInformations(); break; case 163: obj = new CharacterMinimalPlusLookInformations(); break; case 193: obj = new CharacterMinimalPlusLookAndGradeInformations(); break; case 45: obj = new CharacterBaseInformations(); break; case 212: obj = new CharacterToRecolorInformation(); break; case 86: obj = new CharacterHardcoreInformations(); break; case 63: obj = new EntityMovementInformations(); break; case 60: obj = new EntityDispositionInformations(); break; case 107: obj = new IdentifiedEntityDispositionInformations(); break; case 217: obj = new FightEntityDispositionInformations(); break; case 127: obj = new GuildInformations(); break; case 204: obj = new ActorRestrictionsInformations(); break; case 201: obj = new ActorAlignmentInformations(); break; case 183: obj = new PaddockContentInformations(); break; case 184: obj = new MountInformationsForPaddock(); break; case 202: obj = new ActorExtendedAlignmentInformations(); break; case 135: obj = new AlignmentBonusInformations(); break; case 142: obj = new PrismSubAreaInformation(); break; case 152: obj = new PrismConquestInformation(); break; case 187: obj = new TaxCollectorName(); break; case 96: obj = new TaxCollectorBasicInformations(); break; case 4: obj = new CharacterBaseCharacteristic(); break; case 215: obj = new CharacterSpellModification(); break; case 8: obj = new CharacterCharacteristicsInformations(); break; case 117: obj = new FightExternalInformations(); break; case 43: obj = new FightCommonInformations(); break; case 44: obj = new FightTeamMemberInformations(); break; case 13: obj = new FightTeamMemberCharacterInformations(); break; case 6: obj = new FightTeamMemberMonsterInformations(); break; case 177: obj = new FightTeamMemberTaxCollectorInformations(); break; case 20: obj = new FightOptionsInformations(); break; case 116: obj = new AbstractFightTeamInformations(); break; case 33: obj = new FightTeamInformations(); break; case 115: obj = new FightTeamLightInformations(); break; case 31: obj = new GameFightMinimalStats(); break; case 41: obj = new FightLoot(); break; case 16: obj = new FightResultListEntry(); break; case 189: obj = new FightResultFighterListEntry(); break; case 191: obj = new FightResultAdditionalData(); break; case 192: obj = new FightResultExperienceData(); break; case 190: obj = new FightResultPvpData(); break; case 24: obj = new FightResultPlayerListEntry(); break; case 216: obj = new FightResultMutantListEntry(); break; case 84: obj = new FightResultTaxCollectorListEntry(); break; case 206: obj = new AbstractFightDispellableEffect(); break; case 208: obj = new FightDispellableEffectExtendedInformations(); break; case 209: obj = new FightTemporaryBoostEffect(); break; case 210: obj = new FightTriggeredEffect(); break; case 207: obj = new FightTemporarySpellBoostEffect(); break; case 211: obj = new FightTemporaryBoostWeaponDamagesEffect(); break; case 214: obj = new FightTemporaryBoostStateEffect(); break; case 205: obj = new GameFightSpellCooldown(); break; case 7: obj = new Item(); break; case 49: obj = new SpellItem(); break; case 76: obj = new ObjectEffect(); break; case 74: obj = new ObjectEffectString(); break; case 70: obj = new ObjectEffectInteger(); break; case 82: obj = new ObjectEffectMinMax(); break; case 73: obj = new ObjectEffectDice(); break; case 72: obj = new ObjectEffectDate(); break; case 75: obj = new ObjectEffectDuration(); break; case 71: obj = new ObjectEffectCreature(); break; case 81: obj = new ObjectEffectLadder(); break; case 179: obj = new ObjectEffectMount(); break; case 178: obj = new MountClientData(); break; case 168: obj = new ItemDurability(); break; case 85: obj = new GameActionMarkedCell(); break; case 123: obj = new GoldItem(); break; case 124: obj = new ObjectItemMinimalInformation(); break; case 119: obj = new ObjectItemQuantity(); break; case 134: obj = new ObjectItemNotInContainer(); break; case 37: obj = new ObjectItem(); break; case 120: obj = new ObjectItemToSell(); break; case 164: obj = new ObjectItemToSellInBid(); break; case 198: obj = new ObjectItemInRolePlay(); break; case 197: obj = new ObjectItemWithLookInRolePlay(); break; case 199: obj = new OrientedObjectItemWithLookInRolePlay(); break; case 185: obj = new PaddockItem(); break; case 121: obj = new SellerBuyerDescriptor(); break; case 122: obj = new BidExchangerObjectInfo(); break; case 52: obj = new StartupActionAddObject(); break; case 106: obj = new IgnoredInformations(); break; case 105: obj = new IgnoredOnlineInformations(); break; case 78: obj = new FriendInformations(); break; case 92: obj = new FriendOnlineInformations(); break; case 77: obj = new FriendSpouseInformations(); break; case 93: obj = new FriendSpouseOnlineInformations(); break; case 88: obj = new GuildMember(); break; case 87: obj = new GuildEmblem(); break; case 80: obj = new InteractiveElement(); break; case 108: obj = new StatedElement(); break; case 200: obj = new MapObstacle(); break; case 213: obj = new PartyUpdateCommonsInformations(); break; case 90: obj = new PartyMemberInformations(); break; case 97: obj = new JobCrafterDirectorySettings(); break; case 194: obj = new JobCrafterDirectoryEntryPlayerInfo(); break; case 195: obj = new JobCrafterDirectoryEntryJobInfo(); break; case 196: obj = new JobCrafterDirectoryListEntry(); break; case 101: obj = new JobDescription(); break; case 102: obj = new SkillActionDescription(); break; case 103: obj = new SkillActionDescriptionTimed(); break; case 99: obj = new SkillActionDescriptionCollect(); break; case 100: obj = new SkillActionDescriptionCraft(); break; case 104: obj = new SkillActionDescriptionCraftExtended(); break; case 98: obj = new JobExperience(); break; case 111: obj = new HouseInformations(); break; case 112: obj = new HouseInformationsExtended(); break; case 170: obj = new HouseInformationsForGuild(); break; case 132: obj = new PaddockInformations(); break; case 130: obj = new PaddockBuyableInformations(); break; case 133: obj = new PaddockAbandonnedInformations(); break; case 131: obj = new PaddockPrivateInformations(); break; case 150: obj = new GameContextActorInformations(); break; case 141: obj = new GameRolePlayActorInformations(); break; case 157: obj = new HumanInformations(); break; case 153: obj = new HumanWithGuildInformations(); break; case 154: obj = new GameRolePlayNamedActorInformations(); break; case 159: obj = new GameRolePlayHumanoidInformations(); break; case 36: obj = new GameRolePlayCharacterInformations(); break; case 3: obj = new GameRolePlayMutantInformations(); break; case 129: obj = new GameRolePlayMerchantInformations(); break; case 146: obj = new GameRolePlayMerchantWithGuildInformations(); break; case 180: obj = new GameRolePlayMountInformations(); break; case 147: obj = new TaxCollectorStaticInformations(); break; case 148: obj = new GameRolePlayTaxCollectorInformations(); break; case 167: obj = new TaxCollectorInformations(); break; case 166: obj = new TaxCollectorInformationsInWaitForHelpState(); break; case 186: obj = new ProtectedEntityWaitingForHelpInfo(); break; case 169: obj = new TaxCollectorFightersInformation(); break; case 165: obj = new AdditionalTaxCollectorInformations(); break; case 144: obj = new MonsterInGroupInformations(); break; case 140: obj = new GroupMonsterStaticInformations(); break; case 160: obj = new GameRolePlayGroupMonsterInformations(); break; case 155: obj = new NpcStaticInformations(); break; case 156: obj = new GameRolePlayNpcInformations(); break; case 161: obj = new GameRolePlayPrismInformations(); break; case 143: obj = new GameFightFighterInformations(); break; case 158: obj = new GameFightFighterNamedInformations(); break; case 46: obj = new GameFightCharacterInformations(); break; case 50: obj = new GameFightMutantInformations(); break; case 151: obj = new GameFightAIInformations(); break; case 29: obj = new GameFightMonsterInformations(); break; case 203: obj = new GameFightMonsterWithAlignmentInformations(); break; case 48: obj = new GameFightTaxCollectorInformations(); break; case 174: obj = new MapCoordinates(); break; case 176: obj = new MapCoordinatesExtended(); break; case 175: obj = new AtlasPointsInformations(); break; default: throw new Exception("Type with id " + typeId + " is unknown."); } return(obj); }
public override void Deserialize(ICustomDataInput reader) { SubAreaId = reader.ReadVarShort(); MapId = reader.ReadDouble(); var countHouses = reader.ReadShort(); Houses = new List <HouseInformations>(); for (short i = 0; i < countHouses; i++) { var housestypeId = reader.ReadShort(); HouseInformations type = new HouseInformations(); type.Deserialize(reader); Houses.Add(type); } var countActors = reader.ReadShort(); Actors = new List <GameRolePlayActorInformations>(); for (short i = 0; i < countActors; i++) { var actorstypeId = reader.ReadShort(); GameRolePlayActorInformations type = new GameRolePlayActorInformations(); type.Deserialize(reader); Actors.Add(type); } var countInteractiveElements = reader.ReadShort(); InteractiveElements = new List <InteractiveElement>(); for (short i = 0; i < countInteractiveElements; i++) { var interactiveElementstypeId = reader.ReadShort(); InteractiveElement type = new InteractiveElement(); type.Deserialize(reader); InteractiveElements.Add(type); } var countStatedElements = reader.ReadShort(); StatedElements = new List <StatedElement>(); for (short i = 0; i < countStatedElements; i++) { StatedElement type = new StatedElement(); type.Deserialize(reader); StatedElements.Add(type); } var countObstacles = reader.ReadShort(); Obstacles = new List <MapObstacle>(); for (short i = 0; i < countObstacles; i++) { MapObstacle type = new MapObstacle(); type.Deserialize(reader); Obstacles.Add(type); } var countFights = reader.ReadShort(); Fights = new List <FightCommonInformations>(); for (short i = 0; i < countFights; i++) { FightCommonInformations type = new FightCommonInformations(); type.Deserialize(reader); Fights.Add(type); } HasAggressiveMonsters = reader.ReadBoolean(); FightStartPositions = new FightStartingPositions(); FightStartPositions.Deserialize(reader); }
static MapObstacle() { Instance = new MapObstacle(); }
public override void Deserialize(IDataReader reader) { m_subAreaId = reader.ReadVarUhShort(); m_mapId = reader.ReadInt(); int housesCount = reader.ReadUShort(); int housesIndex; m_houses = new System.Collections.Generic.List <HouseInformations>(); for (housesIndex = 0; (housesIndex < housesCount); housesIndex = (housesIndex + 1)) { HouseInformations objectToAdd = ProtocolTypeManager.GetInstance <HouseInformations>(reader.ReadUShort()); objectToAdd.Deserialize(reader); m_houses.Add(objectToAdd); } int actorsCount = reader.ReadUShort(); int actorsIndex; m_actors = new System.Collections.Generic.List <GameRolePlayActorInformations>(); for (actorsIndex = 0; (actorsIndex < actorsCount); actorsIndex = (actorsIndex + 1)) { GameRolePlayActorInformations objectToAdd = ProtocolTypeManager.GetInstance <GameRolePlayActorInformations>(reader.ReadUShort()); objectToAdd.Deserialize(reader); m_actors.Add(objectToAdd); } int interactiveElementsCount = reader.ReadUShort(); int interactiveElementsIndex; m_interactiveElements = new System.Collections.Generic.List <InteractiveElement>(); for (interactiveElementsIndex = 0; (interactiveElementsIndex < interactiveElementsCount); interactiveElementsIndex = (interactiveElementsIndex + 1)) { InteractiveElement objectToAdd = ProtocolTypeManager.GetInstance <InteractiveElement>(reader.ReadUShort()); objectToAdd.Deserialize(reader); m_interactiveElements.Add(objectToAdd); } int statedElementsCount = reader.ReadUShort(); int statedElementsIndex; m_statedElements = new System.Collections.Generic.List <StatedElement>(); for (statedElementsIndex = 0; (statedElementsIndex < statedElementsCount); statedElementsIndex = (statedElementsIndex + 1)) { StatedElement objectToAdd = new StatedElement(); objectToAdd.Deserialize(reader); m_statedElements.Add(objectToAdd); } int obstaclesCount = reader.ReadUShort(); int obstaclesIndex; m_obstacles = new System.Collections.Generic.List <MapObstacle>(); for (obstaclesIndex = 0; (obstaclesIndex < obstaclesCount); obstaclesIndex = (obstaclesIndex + 1)) { MapObstacle objectToAdd = new MapObstacle(); objectToAdd.Deserialize(reader); m_obstacles.Add(objectToAdd); } int fightsCount = reader.ReadUShort(); int fightsIndex; m_fights = new System.Collections.Generic.List <FightCommonInformations>(); for (fightsIndex = 0; (fightsIndex < fightsCount); fightsIndex = (fightsIndex + 1)) { FightCommonInformations objectToAdd = new FightCommonInformations(); objectToAdd.Deserialize(reader); m_fights.Add(objectToAdd); } m_hasAggressiveMonsters = reader.ReadBoolean(); m_fightStartPositions = new FightStartingPositions(); m_fightStartPositions.Deserialize(reader); }
public float getDistanceFrom(MapObstacle o) { double distance = Math.Sqrt(Math.Pow(o.getX() - x, 2) + Math.Pow(o.getY() - y, 2)); return((float)distance); }
private void InitFromFileWorker(string filename) { try { PathfindingType = (PathfindingType)Config.sv_pathfinding; AllodsMap mapStructure = AllodsMap.LoadFrom(filename); if (mapStructure == null) { //Core.Abort("Couldn't load \"{0}\"", filename); GameConsole.Instance.WriteLine("Couldn't load \"{0}\"", filename); Unload(); return; } Width = (int)mapStructure.Data.Width; Height = (int)mapStructure.Data.Height; // load in map.reg // for base terrain costs here Registry reg = null; try { reg = new Registry("world/data/map.reg"); } catch (Exception) { reg = new Registry(); } int[] NodeCosts = new int[] { reg.GetInt("Terrain", "CostLand", 8), reg.GetInt("Terrain", "CostGrass", 8), reg.GetInt("Terrain", "CostFlowers", 9), reg.GetInt("Terrain", "CostSand", 14), reg.GetInt("Terrain", "CostCracked", 6), reg.GetInt("Terrain", "CostStones", 12), reg.GetInt("Terrain", "CostSavanna", 11), reg.GetInt("Terrain", "CostMountain", 16), reg.GetInt("Terrain", "CostWater", 8), reg.GetInt("Terrain", "CostRoad", 6) }; int[] NodeTileTypesInCell = new int[] { 2, 3, 2, 4, 3, 4, 2, 2, 2, 2, 4, 4, 4, 4, 0, 0, 3, 5, 3, 3, 1, 3, 2, 4, 2, 2, 4, 2, 4, 4, 0, 0, 2, 3, 2, 4, 3, 4, 2, 4, 2, 2, 4, 2, 4, 4, 0, 0, 5, 5, 5, 5, 5, 5, 2, 2, 2, 2, 4, 4, 4, 4, 0, 0 }; int[,] NodeTileTypes = new int[16, 2] { { 2, 1 }, { 5, 1 }, { 4, 1 }, { 7, 1 }, { 6, 1 }, { 5, 6 }, { 3, 7 }, { 8, 6 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 10, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; // end loading terrain costs Nodes = new MapNode[Width, Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { MapNode node = Nodes[x, y] = new MapNode(); node.Tile = (ushort)(mapStructure.Tiles[y * Width + x] & 0x3FF); node.Height = mapStructure.Heights[y * Width + x]; node.Flags = 0; node.Light = 255; int costTileType = (node.Tile & 0x3C0) >> 6; int costTileBorder = (node.Tile & 0x3F); float costTileFactor = (NodeTileTypesInCell[costTileBorder] - 1) / 4f; // 1..5 -> 0..4 -> 0..1 int costSubTileType1 = NodeTileTypes[costTileType, 1] - 1; int costSubTileType2 = NodeTileTypes[costTileType, 0] - 1; int costSubTile1 = (costSubTileType1 >= 0) ? NodeCosts[costSubTileType1] : 0; int costSubTile2 = (costSubTileType2 >= 0) ? NodeCosts[costSubTileType2] : 0; node.BaseWalkCost = (byte)((costSubTile1 * (1f - costTileFactor)) + (costSubTile2 * costTileFactor)); // 7 = rock // 8 = water int walkType = costSubTileType1; float walkFactor = 1f - costTileFactor; if (costSubTileType2 == 7 || costSubTileType2 == 8 || costSubTileType1 == -1) { walkType = costSubTileType2; walkFactor = costTileFactor; } if (walkType < 0 || walkType == 8 || (walkType == 7 && walkFactor > 0.25f)) { node.Flags |= MapNodeFlags.BlockedTerrain; } } } // load players foreach (AllodsMap.AlmPlayer almplayer in mapStructure.Players) { Player player = new Player(almplayer); Players.Add(player); //Debug.Log(string.Format("player ID={2} {0} (flags {1})", player.Name, player.Flags, player.ID)); } GameManager.Instance.CallDelegateOnNextFrame(() => { Speed = 5; return(false); }); _TopObjectID = 0; // load obstacles for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { int typeId = mapStructure.Objects[y * Width + x]; if (typeId <= 0) { continue; } typeId -= 1; MapObstacle mob = new MapObstacle(typeId); mob.X = x; mob.Y = y; mob.LinkToWorld(); AddObject(mob, false); } } // load structures if (mapStructure.Structures != null) { foreach (AllodsMap.AlmStructure almstruc in mapStructure.Structures) { MapStructure struc; struc = new MapStructure(almstruc.TypeID); if (struc.Class == null) { Debug.LogFormat("Tried to load invalid structure {0}", almstruc.TypeID); continue; } struc.X = (int)almstruc.X; struc.Y = (int)almstruc.Y; struc.Health = almstruc.Health; struc.Tag = almstruc.ID; struc.Player = GetPlayerByID(almstruc.Player - 1); if (almstruc.IsBridge) { struc.Width = almstruc.Width; struc.Height = almstruc.Height; // also this crutch is apparently done by ROM2 if (struc.Width < 2) { struc.Width = 2; } if (struc.Height < 2) { struc.Height = 2; } struc.IsBridge = true; } // find inn/shop data if needed if (struc.Class != null && struc.Class.Usable) { if ((struc.Class.ID >= 105 && struc.Class.ID <= 107) || // druid shop (struc.Class.ID >= 34 && struc.Class.ID <= 35) || // plagat shop (struc.Class.ID >= 93 && struc.Class.ID <= 95)) // kaarg shop { foreach (AllodsMap.AlmShop shop in mapStructure.Shops) { if (shop.ID == struc.Tag) { struc.Logic = new ShopStructure(struc, shop); break; } } if (struc.Logic == null) { Debug.LogFormat("Warning: Loaded multiplayer shop without data (ID={0})", struc.ID); } } else if ((struc.Class.ID >= 99 && struc.Class.ID <= 101) || // kaarg inn (struc.Class.ID >= 111 && struc.Class.ID <= 113) || // druid inn (struc.Class.ID >= 67 && struc.Class.ID <= 69)) // plagat inn { foreach (AllodsMap.AlmInnInfo info in mapStructure.Inns) { if (info.ID == struc.Tag) { struc.Logic = new InnStructure(struc, info); break; } } if (struc.Logic == null) { Debug.LogFormat("Warning: Loaded multiplayer inn without data (ID={0})", struc.ID); } } } struc.LinkToWorld(); AddObject(struc, (struc.Logic != null)); } } // load groups if (!NetworkManager.IsClient && mapStructure.Groups != null) { foreach (AllodsMap.AlmGroup almgroup in mapStructure.Groups) { Group grp = FindNewGroup((int)almgroup.GroupID); grp.RepopDelay = (int)almgroup.RepopTime * TICRATE; grp.Flags = 0; if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.RandomPositions)) { grp.Flags |= GroupFlags.RandomPositions; } if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.QuestKill)) { grp.Flags |= GroupFlags.QuestKill; } if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.QuestIntercept)) { grp.Flags |= GroupFlags.QuestIntercept; } } } // load units if (!NetworkManager.IsClient && mapStructure.Units != null) { System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); foreach (AllodsMap.AlmUnit almunit in mapStructure.Units) { if ((almunit.Flags & 0x10) != 0) { MapHuman human = new MapHuman(almunit.ServerID); if (human.Class == null) { Debug.LogFormat("Tried to load invalid unit {0}", almunit.ServerID); continue; } human.X = human.TargetX = human.SpawnX = human.LastSpawnX = (int)almunit.X; human.Y = human.TargetY = human.SpawnY = human.LastSpawnY = (int)almunit.Y; human.Tag = almunit.ID; human.Player = GetPlayerByID(almunit.Player - 1); if (almunit.HealthMax >= 0) { human.CoreStats.HealthMax = almunit.HealthMax; human.UpdateItems(); } if (almunit.Health >= 0) { human.Stats.TrySetHealth(almunit.Health); } human.CalculateVision(); human.Group = FindNewGroup(almunit.Group); human.LinkToWorld(); AddObject(human, true); } else { MapUnit unit = new MapUnit(almunit.ServerID); if (unit.Class == null) { Debug.LogFormat("Tried to load invalid unit {0}", almunit.ServerID); continue; } unit.X = unit.TargetX = unit.SpawnX = unit.LastSpawnX = (int)almunit.X; unit.Y = unit.TargetY = unit.SpawnY = unit.LastSpawnY = (int)almunit.Y; unit.Tag = almunit.ID; unit.Player = GetPlayerByID(almunit.Player - 1); if (almunit.HealthMax >= 0) { unit.CoreStats.HealthMax = almunit.HealthMax; unit.UpdateItems(); } if (almunit.Health >= 0) { unit.Stats.TrySetHealth(almunit.Health); } unit.CalculateVision(); unit.Group = FindNewGroup(almunit.Group); unit.LinkToWorld(); AddObject(unit, true); } } } // load items into units if (!NetworkManager.IsClient && mapStructure.Sacks != null) { foreach (AllodsMap.AlmSack almsack in mapStructure.Sacks) { if (almsack.Items.Length <= 0) { continue; } MapUnit unit = null; MapSack sack = null; if (almsack.UnitID != 0) { unit = GetUnitByTag((int)almsack.UnitID); if (unit == null) { Debug.LogFormat("Error: Can't resolve unit ID {0} for sack", almsack.UnitID); continue; } } else { sack = PutSackAt((int)almsack.X, (int)almsack.Y, new ItemPack(), false); sack.Pack.Money += almsack.Gold; } List <Item> items = new List <Item>(); foreach (AllodsMap.AlmSackItem almitem in almsack.Items) { List <ItemEffect> effects = new List <ItemEffect>(); AllodsMap.AlmEffect almBaseEffect = null; int almBaseEffectId = (int)(almitem.EffectNumber - 1); if (mapStructure.Effects != null && almBaseEffectId >= 0 && almBaseEffectId < mapStructure.Effects.Length) { almBaseEffect = mapStructure.Effects[almBaseEffectId]; foreach (AllodsMap.AlmEffectModifier mod in almBaseEffect.EffectModifiers) { ItemEffect effect = new ItemEffect((ItemEffect.Effects)mod.TypeOfMod, (int)mod.Value); effects.Add(effect); } } else if (almBaseEffectId >= 0) { Debug.LogFormat("Warning: Can't resolve effect #{0} for sack item", almBaseEffectId); } Item item = new Item((ushort)almitem.ItemID, effects); if (unit != null) { if (almitem.Wielded > 0) { unit.PutItemToBody((MapUnit.BodySlot)item.Class.Option.Slot, item); } else { unit.ItemsPack.PutItem(unit.ItemsPack.Count, item); } } else if (sack != null) { sack.Pack.PutItem(sack.Pack.Count, item); } } } } //* WB_pathfind if (PathfindingType == PathfindingType.Flood) { Wizard.LoadMap(this); } //* end // only if loaded MapStructure = mapStructure; FileName = filename; FileMD5 = ResourceManager.CalcMD5(FileName); MapLighting = new TerrainLighting(Width, Height); CalculateLighting(180); // postprocessing // if we are playing in singleplayer, then console player is Self. if (!NetworkManager.IsClient && !NetworkManager.IsServer) { Player Self = GetPlayerByName("Self"); if (Self == null) { GameConsole.Instance.WriteLine("Error: couldn't set ConsolePlayer: Self not found!"); } else { ConsolePlayer = Self; } if (ConsolePlayer != null) { ConsolePlayer.Name = Config.cl_nickname.Length == 0 ? "Self" : Config.cl_nickname; ConsolePlayer.Flags = 0; ConsolePlayer.Diplomacy[ConsolePlayer.ID] = DiplomacyFlags.Ally | DiplomacyFlags.Vision; GameManager.Instance.CallDelegateOnNextFrame(() => { ConsolePlayer.Avatar = CreateAvatar(ConsolePlayer); // center view on avatar. MapView.Instance.CenterOnObject(ConsolePlayer.Avatar); return(false); }); } } if (!NetworkManager.IsClient) { // testing /* * ItemPack testpack = new ItemPack(); * testpack.PutItem(0, new Item("Very Rare Crystal Ring")); * PutSackAt(16, 16, testpack, false); */ /* * MapProjectile proj = new MapProjectile(15); * proj.SetPosition(16, 16, 0); * Objects.Add(proj); */ } GameManager.Instance.CallDelegateOnNextFrame(() => { MapView.Instance.OnMapLoaded(); return(false); }); } catch (Exception e) { Debug.LogError(e); GameConsole.Instance.WriteLine("Failed to load {0}: {1}: {2}", filename, e.GetType().Name, e.Message); MapStructure = null; } finally { IsLoading = false; } }
public static void ObjectBecameVisible(Player player, MapObject mobj) { if (player.NetClient == null) { return; } //Debug.LogFormat("visible = {0}->{1}", player.Name, mobj.GetObjectType().ToString()); if (mobj.GetObjectType() == MapObjectType.Monster || mobj.GetObjectType() == MapObjectType.Human) { MapUnit unit = (MapUnit)mobj; ClientCommands.AddUnit unitCmd; unitCmd.Tag = unit.Tag; unitCmd.X = unit.X; unitCmd.Y = unit.Y; unitCmd.Angle = unit.Angle; unitCmd.Player = unit.Player.ID; unitCmd.ServerID = unit.ServerID; unitCmd.CurrentStats = unit.Stats; unitCmd.IsAvatar = (unit == unit.Player.Avatar); unitCmd.VState = unit.VState; unitCmd.IdleFrame = unit.IdleFrame; unitCmd.IdleTime = unit.IdleTime; unitCmd.MoveFrame = unit.MoveFrame; unitCmd.MoveTime = unit.MoveTime; unitCmd.FracX = unit.FracX; unitCmd.FracY = unit.FracY; unitCmd.AttackFrame = unit.AttackFrame; unitCmd.AttackTime = unit.AttackTime; unitCmd.DeathFrame = unit.DeathFrame; unitCmd.DeathTime = unit.DeathTime; unitCmd.IsAlive = unit.IsAlive; unitCmd.IsDying = unit.IsDying; unitCmd.IsHuman = (unit.GetObjectType() == MapObjectType.Human); if (unitCmd.IsHuman) { MapHuman human = (MapHuman)unit; unitCmd.IsHero = human.IsHero; } else { unitCmd.IsHero = false; } unitCmd.ItemsBody = new List <NetItem>(); for (int i = 0; i < unit.ItemsBody.Count; i++) { unitCmd.ItemsBody.Add(new NetItem(unit.ItemsBody[i])); } unitCmd.ItemsPack = new List <NetItem>(); if (unit.Player == player) { for (int i = 0; i < unit.ItemsPack.Count; i++) { unitCmd.ItemsPack.Add(new NetItem(unit.ItemsPack[i])); } } uint sps = 0; foreach (Spell cspell in unit.SpellBook) { sps |= 1u << (int)cspell.SpellID; } unitCmd.SpellBook = sps; player.NetClient.SendCommand(unitCmd); // also notify of current unit state NotifyAddUnitActionsSingle(player.NetClient, unit, unit.Actions.Skip(1).ToArray()); //Debug.LogFormat("sending player {0} unit {1}", player.Name, unitCmd.Tag); } else if (mobj.GetObjectType() == MapObjectType.Sack) { MapSack sack = (MapSack)mobj; NotifySack(sack.X, sack.Y, sack.Pack.Price); } else if (mobj.GetObjectType() == MapObjectType.Obstacle) { MapObstacle obstacle = (MapObstacle)mobj; if (obstacle.IsDead) { Server.NotifyStaticObjectDead(obstacle.X, obstacle.Y); } } }
private void InitFromFileWorker(string filename) { try { AllodsMap mapStructure = AllodsMap.LoadFrom(filename); if (mapStructure == null) { //Core.Abort("Couldn't load \"{0}\"", filename); GameConsole.Instance.WriteLine("Couldn't load \"{0}\"", filename); Unload(); return; } Width = (int)mapStructure.Data.Width; Height = (int)mapStructure.Data.Height; Nodes = new MapNode[Width, Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Nodes[x, y] = new MapNode(); Nodes[x, y].Tile = (ushort)(mapStructure.Tiles[y * Width + x] & 0x3FF); Nodes[x, y].Height = mapStructure.Heights[y * Width + x]; Nodes[x, y].Flags = 0; Nodes[x, y].Light = 255; } } // load players foreach (AllodsMap.AlmPlayer almplayer in mapStructure.Players) { Player player = new Player(almplayer); Players.Add(player); //Debug.Log(string.Format("player ID={2} {0} (flags {1})", player.Name, player.Flags, player.ID)); } GameManager.Instance.CallDelegateOnNextFrame(() => { Speed = 5; return(false); }); _TopObjectID = 0; // load obstacles for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { int typeId = mapStructure.Objects[y * Width + x]; if (typeId <= 0) { continue; } typeId -= 1; MapObstacle mob = new MapObstacle(typeId); mob.X = x; mob.Y = y; mob.LinkToWorld(); Objects.Add(mob); } } // load structures if (mapStructure.Structures != null) { foreach (AllodsMap.AlmStructure almstruc in mapStructure.Structures) { MapStructure struc; struc = new MapStructure(almstruc.TypeID); struc.X = (int)almstruc.X; struc.Y = (int)almstruc.Y; struc.Health = almstruc.Health; struc.Tag = almstruc.ID; struc.Player = GetPlayerByID(almstruc.Player - 1); if (almstruc.IsBridge) { struc.Width = almstruc.Width; struc.Height = almstruc.Height; // also this crutch is apparently done by ROM2 if (struc.Width < 2) { struc.Width = 2; } if (struc.Height < 2) { struc.Height = 2; } struc.IsBridge = true; } struc.LinkToWorld(); Objects.Add(struc); } } // load groups if (!NetworkManager.IsClient && mapStructure.Groups != null) { foreach (AllodsMap.AlmGroup almgroup in mapStructure.Groups) { Group grp = FindNewGroup((int)almgroup.GroupID); grp.RepopDelay = (int)almgroup.RepopTime * TICRATE; grp.Flags = 0; if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.RandomPositions)) { grp.Flags |= GroupFlags.RandomPositions; } if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.QuestKill)) { grp.Flags |= GroupFlags.QuestKill; } if (almgroup.GroupFlag.HasFlag(AllodsMap.AlmGroup.AlmGroupFlags.QuestIntercept)) { grp.Flags |= GroupFlags.QuestIntercept; } } } // load units if (!NetworkManager.IsClient && mapStructure.Units != null) { int c = 0; System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); foreach (AllodsMap.AlmUnit almunit in mapStructure.Units) { if ((almunit.Flags & 0x10) != 0) { MapHuman human = new MapHuman(almunit.ServerID); human.X = human.TargetX = human.SpawnX = human.LastSpawnX = (int)almunit.X; human.Y = human.TargetY = human.SpawnY = human.LastSpawnY = (int)almunit.Y; human.Tag = almunit.ID; human.Player = GetPlayerByID(almunit.Player - 1); if (almunit.HealthMax >= 0) { human.CoreStats.HealthMax = almunit.HealthMax; human.UpdateItems(); } if (almunit.Health >= 0) { human.Stats.TrySetHealth(almunit.Health); } human.CalculateVision(); human.Group = FindNewGroup(almunit.Group); human.LinkToWorld(); Objects.Add(human); } else { MapUnit unit = new MapUnit(almunit.ServerID); unit.X = unit.TargetX = unit.SpawnX = unit.LastSpawnX = (int)almunit.X; unit.Y = unit.TargetY = unit.SpawnY = unit.LastSpawnY = (int)almunit.Y; unit.Tag = almunit.ID; unit.Player = GetPlayerByID(almunit.Player - 1); if (almunit.HealthMax >= 0) { unit.CoreStats.HealthMax = almunit.HealthMax; unit.UpdateItems(); } if (almunit.Health >= 0) { unit.Stats.TrySetHealth(almunit.Health); } unit.CalculateVision(); unit.Group = FindNewGroup(almunit.Group); unit.LinkToWorld(); Objects.Add(unit); } } } // only if loaded MapStructure = mapStructure; FileName = filename; FileMD5 = ResourceManager.CalcMD5(FileName); MapLighting = new TerrainLighting(Width, Height); CalculateLighting(180); // postprocessing // if we are playing in singleplayer, then console player is Self. if (!NetworkManager.IsClient && !NetworkManager.IsServer) { Player Self = GetPlayerByName("Self"); if (Self == null) { GameConsole.Instance.WriteLine("Error: couldn't set ConsolePlayer: Self not found!"); } else { ConsolePlayer = Self; } if (ConsolePlayer != null) { ConsolePlayer.Name = Config.cl_nickname.Length == 0 ? "Self" : Config.cl_nickname; ConsolePlayer.Flags = 0; ConsolePlayer.Diplomacy[ConsolePlayer.ID] = DiplomacyFlags.Ally | DiplomacyFlags.Vision; GameManager.Instance.CallDelegateOnNextFrame(() => { ConsolePlayer.Avatar = CreateAvatar(ConsolePlayer); // center view on avatar. MapView.Instance.CenterOnObject(ConsolePlayer.Avatar); return(false); }); } } if (!NetworkManager.IsClient) { // testing /* * ItemPack testpack = new ItemPack(); * testpack.PutItem(0, new Item("Very Rare Crystal Ring")); * PutSackAt(16, 16, testpack, false); */ /* * MapProjectile proj = new MapProjectile(15); * proj.SetPosition(16, 16, 0); * Objects.Add(proj); */ } /* WarBeginner */ Wizard.LoadMap(this); GameManager.Instance.CallDelegateOnNextFrame(() => { MapView.Instance.OnMapLoaded(); return(false); }); } catch (Exception e) { Debug.LogError(e); GameConsole.Instance.WriteLine("Failed to load {0}: {1}: {2}", filename, e.GetType().Name, e.Message); MapStructure = null; } finally { IsLoading = false; } }
public override void Deserialize(IDataReader reader) { this.subAreaId = (uint)reader.ReadVarUhShort(); if (this.subAreaId < 0U) { throw new Exception("Forbidden value (" + (object)this.subAreaId + ") on element of MapComplementaryInformationsDataMessage.subAreaId."); } this.mapId = reader.ReadDouble(); if (this.mapId < 0.0 || this.mapId > 9.00719925474099E+15) { throw new Exception("Forbidden value (" + (object)this.mapId + ") on element of MapComplementaryInformationsDataMessage.mapId."); } uint num1 = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num1; ++index) { HouseInformations instance = ProtocolTypeManager.GetInstance <HouseInformations>((uint)reader.ReadUShort()); instance.Deserialize(reader); this.houses.Add(instance); } uint num2 = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num2; ++index) { GameRolePlayActorInformations instance = ProtocolTypeManager.GetInstance <GameRolePlayActorInformations>((uint)reader.ReadUShort()); instance.Deserialize(reader); this.actors.Add(instance); } uint num3 = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num3; ++index) { InteractiveElement instance = ProtocolTypeManager.GetInstance <InteractiveElement>((uint)reader.ReadUShort()); instance.Deserialize(reader); this.interactiveElements.Add(instance); } uint num4 = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num4; ++index) { StatedElement statedElement = new StatedElement(); statedElement.Deserialize(reader); this.statedElements.Add(statedElement); } uint num5 = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num5; ++index) { MapObstacle mapObstacle = new MapObstacle(); mapObstacle.Deserialize(reader); this.obstacles.Add(mapObstacle); } uint num6 = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num6; ++index) { FightCommonInformations commonInformations = new FightCommonInformations(); commonInformations.Deserialize(reader); this.fights.Add(commonInformations); } this.hasAggressiveMonsters = reader.ReadBoolean(); this.fightStartPositions = new FightStartingPositions(); this.fightStartPositions.Deserialize(reader); }
public void InitFromFile(string filename) { Unload(); InitGeneric(); AllodsMap mapStructure = AllodsMap.LoadFrom(filename); if (mapStructure == null) { //Core.Abort("Couldn't load \"{0}\"", filename); GameConsole.Instance.WriteLine("Couldn't load \"{0}\"", filename); Unload(); return; } Width = (int)mapStructure.Data.Width; Height = (int)mapStructure.Data.Height; Nodes = new MapNode[Width, Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Nodes[x, y] = new MapNode(); Nodes[x, y].Tile = (ushort)(mapStructure.Tiles[y * Width + x] & 0x3FF); Nodes[x, y].Height = mapStructure.Heights[y * Width + x]; Nodes[x, y].Flags = 0; Nodes[x, y].Light = 255; } } // load players foreach (AllodsMap.AlmPlayer almplayer in mapStructure.Players) { Player player = new Player(almplayer); Players.Add(player); //Debug.Log(string.Format("player ID={2} {0} (flags {1})", player.Name, player.Flags, player.ID)); } GameManager.Instance.CallDelegateOnNextFrame(() => { Speed = 5; return(false); }); _TopObjectID = 0; // load obstacles for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { int typeId = mapStructure.Objects[y * Width + x]; if (typeId <= 0) { continue; } typeId -= 1; MapObstacle mob = new MapObstacle(typeId); mob.X = x; mob.Y = y; mob.LinkToWorld(); Objects.Add(mob); } } // load structures if (mapStructure.Structures != null) { foreach (AllodsMap.AlmStructure almstruc in mapStructure.Structures) { MapStructure struc; struc = new MapStructure(almstruc.TypeID); struc.X = (int)almstruc.X; struc.Y = (int)almstruc.Y; struc.Health = almstruc.Health; struc.Tag = almstruc.ID; struc.Player = GetPlayerByID(almstruc.Player - 1); if (almstruc.IsBridge) { struc.Width = almstruc.Width; struc.Height = almstruc.Height; // also this crutch is apparently done by ROM2 if (struc.Width < 2) { struc.Width = 2; } if (struc.Height < 2) { struc.Height = 2; } struc.IsBridge = true; } struc.LinkToWorld(); Objects.Add(struc); } } // load units if (!NetworkManager.IsClient && mapStructure.Units != null) { foreach (AllodsMap.AlmUnit almunit in mapStructure.Units) { if ((almunit.Flags & 0x10) != 0) { MapHuman human = new MapHuman(almunit.ServerID); human.X = (int)almunit.X; human.Y = (int)almunit.Y; human.Tag = almunit.ID; human.Player = GetPlayerByID(almunit.Player - 1); if (almunit.HealthMax >= 0) { human.Stats.HealthMax = almunit.HealthMax; } if (almunit.Health >= 0) { human.Stats.TrySetHealth(almunit.Health); } human.LinkToWorld(); Objects.Add(human); } else { MapUnit unit = new MapUnit(almunit.ServerID); unit.X = (int)almunit.X; unit.Y = (int)almunit.Y; unit.Tag = almunit.ID; unit.Player = GetPlayerByID(almunit.Player - 1); if (almunit.HealthMax >= 0) { unit.Stats.HealthMax = almunit.HealthMax; } if (almunit.Health >= 0) { unit.Stats.TrySetHealth(almunit.Health); } unit.LinkToWorld(); Objects.Add(unit); } } } // only if loaded MapStructure = mapStructure; FileName = filename; FileMD5 = ResourceManager.CalcMD5(FileName); MapLighting = new TerrainLighting(Width, Height); CalculateLighting(180); // postprocessing // if we are playing in singleplayer, then console player is Self. if (!NetworkManager.IsClient && !NetworkManager.IsServer) { Player Self = GetPlayerByName("Self"); if (Self == null) { GameConsole.Instance.WriteLine("Error: couldn't set ConsolePlayer: Self not found!"); } else { ConsolePlayer = Self; } if (ConsolePlayer != null) { ConsolePlayer.Flags = 0; ConsolePlayer.Diplomacy[ConsolePlayer.ID] = DiplomacyFlags.Ally | DiplomacyFlags.Vision; GameManager.Instance.CallDelegateOnNextFrame(() => { ConsolePlayer.Avatar = CreateAvatar(ConsolePlayer); // center view on avatar. MapView.Instance.CenterOnObject(ConsolePlayer.Avatar); return(false); }); } } if (!NetworkManager.IsClient) { // testing /* * ItemPack testpack = new ItemPack(); * testpack.PutItem(0, new Item("Very Rare Crystal Ring")); * PutSackAt(16, 16, testpack, false); */ /* * MapProjectile proj = new MapProjectile(15); * proj.SetPosition(16, 16, 0); * Objects.Add(proj); */ } }
public override void Deserialize(IDataReader reader) { SubAreaId = reader.ReadVarUhShort(); MapId = reader.ReadDouble(); var housesCount = reader.ReadUShort(); Houses = new List <HouseInformations>(); for (var housesIndex = 0; housesIndex < housesCount; housesIndex++) { var objectToAdd = ProtocolTypeManager.GetInstance <HouseInformations>(reader.ReadUShort()); objectToAdd.Deserialize(reader); Houses.Add(objectToAdd); } var actorsCount = reader.ReadUShort(); Actors = new List <GameRolePlayActorInformations>(); for (var actorsIndex = 0; actorsIndex < actorsCount; actorsIndex++) { var objectToAdd = ProtocolTypeManager.GetInstance <GameRolePlayActorInformations>(reader.ReadUShort()); objectToAdd.Deserialize(reader); Actors.Add(objectToAdd); } var interactiveElementsCount = reader.ReadUShort(); InteractiveElements = new List <InteractiveElement>(); for (var interactiveElementsIndex = 0; interactiveElementsIndex < interactiveElementsCount; interactiveElementsIndex++) { var objectToAdd = ProtocolTypeManager.GetInstance <InteractiveElement>(reader.ReadUShort()); objectToAdd.Deserialize(reader); InteractiveElements.Add(objectToAdd); } var statedElementsCount = reader.ReadUShort(); StatedElements = new List <StatedElement>(); for (var statedElementsIndex = 0; statedElementsIndex < statedElementsCount; statedElementsIndex++) { var objectToAdd = new StatedElement(); objectToAdd.Deserialize(reader); StatedElements.Add(objectToAdd); } var obstaclesCount = reader.ReadUShort(); Obstacles = new List <MapObstacle>(); for (var obstaclesIndex = 0; obstaclesIndex < obstaclesCount; obstaclesIndex++) { var objectToAdd = new MapObstacle(); objectToAdd.Deserialize(reader); Obstacles.Add(objectToAdd); } var fightsCount = reader.ReadUShort(); Fights = new List <FightCommonInformations>(); for (var fightsIndex = 0; fightsIndex < fightsCount; fightsIndex++) { var objectToAdd = new FightCommonInformations(); objectToAdd.Deserialize(reader); Fights.Add(objectToAdd); } HasAggressiveMonsters = reader.ReadBoolean(); FightStartPositions = new FightStartingPositions(); FightStartPositions.Deserialize(reader); }