public static void DropItem(MapHuman human, Item item, int x, int y) { if (NetworkManager.IsClient) { // check what this item is. if (item.Parent == human.ItemsBody) { SendItemMove(ServerCommands.ItemMoveLocation.UnitBody, ServerCommands.ItemMoveLocation.Ground, item.Class.Option.Slot, -1, item.Count, human, x, y); } else if (item.Parent == human.ItemsPack) { SendItemMove(ServerCommands.ItemMoveLocation.UnitPack, ServerCommands.ItemMoveLocation.Ground, item.Index, -1, item.Count, human, x, y); } } else { // check coordinates if (Math.Abs(human.X - x) > 2 || Math.Abs(human.Y - y) > 2) { x = human.X; y = human.Y; } ItemPack pack = new ItemPack(); pack.PutItem(0, new Item(item, item.Count)); MapLogic.Instance.PutSackAt(x, y, pack, false); } }
public bool ProcessDrop(Item item, float x, float y) { // //throw new NotImplementedException(); // disregard x/y, as we got MouseCellX/MouseCellY. //Debug.LogFormat("dropping {0} of {1}", item.Count, item.ToString()); MapHuman human = (MapHuman)SelectedObject; Client.DropItem(human, item, MouseCellX, MouseCellY); return(true); }
private float GetMindModifier() { float mmod = 1f; if (User != null && Item == null && User is MapHuman) { MapHuman huser = (MapHuman)User; mmod = (float)huser.Stats.Mind * 0.02f; } return(mmod); }
public void SetPack(MapHuman human) { if (human != null && human.Player == MapLogic.Instance.ConsolePlayer) { View.Pack = human.ItemsPack; View.AutoDropTarget = (IUiItemAutoDropper)human.GameScript; } else { View.Pack = null; View.AutoDropTarget = null; } }
// create main unit for player. public MapUnit CreateAvatar(Player player) { MapUnit unit = new MapUnit(Config.sv_avatar); if (unit.Class == null) { unit = new MapHuman(Config.sv_avatar, true); } if (unit.Class == null) { return(null); } unit.Player = player; unit.Tag = GetFreeUnitTag(); // this is also used as network ID. unit.SetPosition(16, 16, false); unit.LinkToWorld(); AddObject(unit, true); // add items for testing unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Meteoric Amulet {skillfire=100,skillwater=100,skillair=100,skillearth=100,skillastral=100,manamax=16000}")); // for testing mage unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Ring {body=3,scanrange=1,spirit=1}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Amulet {body=3,scanrange=1,spirit=1}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Dragon Leather Large Shield {body=3,protectionearth=20,damagebonus=20}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Plate Helm {body=3,scanrange=2}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Plate Cuirass {body=3}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Plate Bracers {body=3}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Scale Gauntlets {body=3}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Plate Boots {body=3}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Crystal Pike {tohit=500,damagemin=10,damagemax=20}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Meteoric Crossbow {damagemax=500}")); unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Very Rare Magic Wood Staff {castSpell=Drain_Life:100}")); for (int i = 0; i < 50; i++) { unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Scroll Light-")); } for (int i = 0; i < 50; i++) { unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item("Scroll Darkness")); } // add money for testing unit.Player.Money = 12000000000; return(unit); }
// create main unit for player. public MapUnit CreateAvatar(Player player) { MapUnit unit = new MapUnit(Config.sv_avatar); if (unit.Class == null) { unit = new MapHuman(Config.sv_avatar, true); } if (unit.Class == null) { return(null); } unit.Player = player; unit.Tag = GetFreeUnitTag(); // this is also used as network ID. unit.SetPosition(16, 16); Objects.Add(unit); return(unit); }
public bool Process() { if (!MapLogic.Instance.IsLoaded) { return(false); } MapUnit unit = MapLogic.Instance.GetUnitByTag(Tag); if (unit == null || !(unit is MapHuman)) { Debug.LogFormat("Attempted to set experience for nonexistent human {0}", Tag); return(true); } MapHuman human = (MapHuman)unit; human.SetSkillExperience(Skill, ExpAfter, Message); return(true); }
public static void NotifyHumanLevelUp(MapHuman human, MapHuman.ExperienceSkill sk, int newexp, bool message) { foreach (ServerClient client in ServerManager.Clients) { if (client.State != ClientState.Playing) { continue; } Player p = MapLogic.Instance.GetNetPlayer(client); if (human.IsVisibleForNetPlayer(p)) { ClientCommands.HumanLevelUp lvlCmd; lvlCmd.Tag = human.Tag; lvlCmd.ExpAfter = newexp; lvlCmd.Skill = sk; lvlCmd.Message = message; client.SendCommand(lvlCmd); } } }
public void spawn(string unitName) { if (NetworkManager.IsClient || MapLogic.Instance.ConsolePlayer == null) { return; } MapUnit consoleMainChar = MapLogic.Instance.ConsolePlayer.Avatar; if (consoleMainChar == null) { return; } MapUnit unit = new MapHuman(unitName); if (unit.Class == null) { unit = new MapUnit(unitName); } if (unit.Class == null) { GameConsole.Instance.WriteLine("Failed to spawn summoned unit {0}", unitName); return; } unit.Player = MapLogic.Instance.ConsolePlayer; unit.Tag = MapLogic.Instance.GetFreeUnitTag(); if (!unit.RandomizePosition(consoleMainChar.X, consoleMainChar.Y, 2, false)) { // invalid position, don't add unit unit.Dispose(); GameConsole.Instance.WriteLine("No space for summoned unit {0}", unitName); return; } MapLogic.Instance.AddObject(unit, true); }
public bool Process() { //Debug.LogFormat("added unit {0}", Tag); if (!MapLogic.Instance.IsLoaded) { return(false); } MapUnit unit = MapLogic.Instance.GetUnitByTag(Tag); bool newUnit = false; if (unit == null) { if (IsHuman) { unit = new MapHuman(ServerID, IsHero); } else { unit = new MapUnit(ServerID); } if (unit.Class == null) { return(false); // invalid unit created } unit.Tag = Tag; newUnit = true; } Player player = MapLogic.Instance.GetPlayerByID(Player); if (player == null) { Debug.LogFormat("Unable to resolve player {0} for unit {1}", Player, Tag); return(false); } unit.Player = player; unit.IsAlive = IsAlive; unit.IsDying = IsDying; unit.SetPosition(X, Y, true); unit.LinkToWorld(); if (IsAvatar) { unit.Player.Avatar = unit; if (player == MapLogic.Instance.ConsolePlayer) { MapView.Instance.CenterOnObject(unit); } } unit.Actions.RemoveRange(1, unit.Actions.Count - 1); // clear states. unit.Angle = Angle; unit.Stats = CurrentStats; unit.VState = VState; unit.IdleFrame = IdleFrame; unit.IdleTime = IdleTime; unit.MoveFrame = MoveFrame; unit.MoveTime = MoveTime; unit.FracX = FracX; unit.FracY = FracY; unit.AttackFrame = AttackFrame; unit.AttackTime = AttackTime; unit.DeathFrame = DeathFrame; unit.DeathTime = DeathTime; unit.BoneFrame = BoneFrame; unit.CoreStats.HealthMax = HealthMax; unit.CoreStats.ManaMax = ManaMax; unit.SummonTimeMax = SummonTimeMax; unit.SummonTime = SummonTime; unit.ItemsBody.Clear(); if (ItemsBody != null) { for (int i = 0; i < ItemsBody.Count; i++) { unit.ItemsBody.PutItem(unit.ItemsBody.Count, new Item(ItemsBody[i])); } } unit.UpdateItems(); unit.ItemsPack.Clear(); if (ItemsPack != null) { for (int i = 0; i < ItemsPack.Count; i++) { unit.ItemsPack.PutItem(unit.ItemsPack.Count, new Item(ItemsPack[i])); } } if (newUnit) { MapLogic.Instance.AddObject(unit, true); } else { unit.DoUpdateView = true; // update view if unit already present on map (otherwise its automatically done) unit.DoUpdateInfo = true; } // add spells unit.SpellBook.Clear(); for (int i = 0; i < 32; i++) { uint sp = 1u << i; if ((SpellBook & sp) != 0) { Spell cspell = new Spell(i, unit); unit.SpellBook.Add(cspell); } } unit.Update(); // set isalive/isdying return(true); }
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 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); } } }
public void DisplayInfo(bool on, Transform parent) { if (on) { if (InfoObject == null) { InfoObject = Utils.CreateObject(); InfoObject.name = "MapViewUnit$InfoText"; Color colorCaption = new Color32(0xBD, 0x9E, 0x4A, 0xFF); Color colorValue = new Color32(0x6B, 0x9A, 0x7B, 0xFF); Info_Name = DisplayInfoInit(Font.Align.Center, 39, 19, 70, 10, colorCaption); Info_LifeCaption = DisplayInfoInit(Font.Align.Center, 85, 45, 58, 10, colorCaption); Info_Life = DisplayInfoInit(Font.Align.Center, 85, 45, 58, 10, colorValue); Info_BRMSCaption = DisplayInfoInit(Font.Align.Left, 7, 45, 73, 39, colorCaption); Info_BRMS = DisplayInfoInit(Font.Align.Right, 7, 45, 73, 39, colorValue); Info_DamageCaption = DisplayInfoInit(Font.Align.Left, 7, 89, 63, 18, colorCaption); Info_Damage = DisplayInfoInit(Font.Align.Right, 7, 89, 63, 18, colorValue); Info_DefenseCaption = DisplayInfoInit(Font.Align.Left, 75, 89, 65, 18, colorCaption); Info_Defense = DisplayInfoInit(Font.Align.Right, 75, 89, 65, 18, colorValue); Info_ResistCaptionMain = DisplayInfoInit(Font.Align.Left, 75, 113, 65, 8, new Color32(0x94, 0x59, 0x00, 0xFF)); Info_ResistCaption = DisplayInfoInit(Font.Align.Left, 75, 123, 65, 48, colorCaption); Info_Resist = DisplayInfoInit(Font.Align.Right, 75, 123, 65, 48, colorValue); Info_SkillCaptionMain = DisplayInfoInit(Font.Align.Left, 7, 113, 63, 8, new Color32(0x94, 0x59, 0x00, 0xFF)); Info_SkillCaption = DisplayInfoInit(Font.Align.Left, 7, 123, 63, 48, colorCaption); Info_Skill = DisplayInfoInit(Font.Align.Right, 7, 123, 63, 48, colorValue); Info_ScanSpeedCaption = DisplayInfoInit(Font.Align.Left, 41, 201, 65, 18, colorCaption); Info_ScanSpeed = DisplayInfoInit(Font.Align.Right, 41, 201, 65, 18, colorValue); Info_ExperienceCaption = DisplayInfoInit(Font.Align.Left, 16, 187, 110, 8, colorCaption); Info_Experience = DisplayInfoInit(Font.Align.Right, 16, 187, 110, 8, colorValue); } InfoObject.transform.parent = parent; InfoObject.transform.localPosition = new Vector3(0, 0, -0.2f); InfoObject.transform.localScale = new Vector3(1, 1, 1); InfoObject.SetActive(true); if (LogicUnit.Player != null && LogicUnit.Player.Avatar == LogicUnit) { Info_Name.Text = LogicUnit.Player.Name; } else { Info_Name.Text = "\n" + Locale.UnitName[LogicUnit.Class.ID]; } string lifeCaption = Locale.Main[19]; string lifeValue = string.Format("\n{0}/{1}", LogicUnit.Stats.Health, LogicUnit.Stats.HealthMax); if (LogicUnit.Stats.ManaMax > 0) { lifeCaption += "\n\n" + Locale.Main[20]; lifeValue += string.Format("\n\n{0}/{1}", LogicUnit.Stats.Mana, LogicUnit.Stats.ManaMax); } Info_LifeCaption.Text = lifeCaption; Info_Life.Text = lifeValue; Info_BRMSCaption.Text = string.Format("{0}\n{1}\n{2}\n{3}", Locale.Main[15], Locale.Main[16], Locale.Main[17], Locale.Main[18]); Info_BRMS.Text = string.Format("{0}\n{1}\n{2}\n{3}", LogicUnit.Stats.Body, LogicUnit.Stats.Reaction, LogicUnit.Stats.Mind, LogicUnit.Stats.Spirit); Info_DamageCaption.Text = string.Format("{0}\n{1}", Locale.Main[23], Locale.Main[25]); Info_Damage.Text = string.Format("{0}-{1}\n{2}", LogicUnit.Stats.DamageMin, LogicUnit.Stats.DamageMax, LogicUnit.Stats.ToHit); Info_DefenseCaption.Text = string.Format("{0}\n{1}", Locale.Main[24], Locale.Main[26]); Info_Defense.Text = string.Format("{0}\n{1}", LogicUnit.Stats.Absorbtion, LogicUnit.Stats.Defence); Info_ResistCaptionMain.Text = Locale.Main[28]; Info_ResistCaption.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", Locale.Main[41], Locale.Main[42], Locale.Main[43], Locale.Main[44], Locale.Main[45]); Info_Resist.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", LogicUnit.Stats.ProtectionFire, LogicUnit.Stats.ProtectionWater, LogicUnit.Stats.ProtectionAir, LogicUnit.Stats.ProtectionEarth, LogicUnit.Stats.ProtectionAstral); // parts of human info here. if (LogicUnit is MapHuman) { Info_SkillCaptionMain.Text = Locale.Main[27]; MapHuman human = (MapHuman)LogicUnit; if ((human.Gender & MapHuman.GenderFlags.Mage) != 0) { Info_SkillCaption.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", Locale.Main[36], Locale.Main[37], Locale.Main[38], Locale.Main[39], Locale.Main[40]); Info_Skill.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", LogicUnit.Stats.SkillFire, LogicUnit.Stats.SkillWater, LogicUnit.Stats.SkillAir, LogicUnit.Stats.SkillEarth, LogicUnit.Stats.SkillAstral); } else if ((human.Gender & MapHuman.GenderFlags.Fighter) != 0) { Info_SkillCaption.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", Locale.Main[30], Locale.Main[31], Locale.Main[32], Locale.Main[33], Locale.Main[34]); Info_Skill.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", LogicUnit.Stats.SkillBlade, LogicUnit.Stats.SkillAxe, LogicUnit.Stats.SkillBludgeon, LogicUnit.Stats.SkillPike, LogicUnit.Stats.SkillShooting); } else { Info_SkillCaptionMain.Text = Locale.Main[28]; Info_SkillCaption.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", Locale.Main[30], Locale.Main[31], Locale.Main[32], Locale.Main[33], Locale.Main[34]); Info_Skill.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", LogicUnit.Stats.ProtectionBlade, LogicUnit.Stats.ProtectionAxe, LogicUnit.Stats.ProtectionBludgeon, LogicUnit.Stats.ProtectionPike, LogicUnit.Stats.ProtectionShooting); } // display exp Info_ExperienceCaption.Text = Locale.Main[46]; Info_Experience.Text = human.GetExperience().ToString(); } else { Info_SkillCaptionMain.Text = Locale.Main[28]; Info_SkillCaption.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", Locale.Main[30], Locale.Main[31], Locale.Main[32], Locale.Main[33], Locale.Main[34]); Info_Skill.Text = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", LogicUnit.Stats.ProtectionBlade, LogicUnit.Stats.ProtectionAxe, LogicUnit.Stats.ProtectionBludgeon, LogicUnit.Stats.ProtectionPike, LogicUnit.Stats.ProtectionShooting); Info_ExperienceCaption.Text = Info_Experience.Text = ""; } Info_ScanSpeedCaption.Text = string.Format("{0}\n{1}", Locale.Main[21], Locale.Main[22]); Info_ScanSpeed.Text = string.Format("{0:F1}\n{1}", LogicUnit.Stats.ScanRange, LogicUnit.Stats.Speed); } else { if (InfoObject != null) { InfoObject.SetActive(false); } } }
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; } }
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; } }