Beispiel #1
0
        public MailInfo(BinaryReader reader, int version, int customversion)
        {
            MailID         = reader.ReadUInt64();
            Sender         = reader.ReadString();
            RecipientIndex = reader.ReadInt32();
            Message        = reader.ReadString();
            Gold           = reader.ReadUInt32();

            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                UserItem item = new UserItem(reader, version, customversion);
                if (Envir.BindItem(item))
                {
                    Items.Add(item);
                }
            }

            DateSent   = DateTime.FromBinary(reader.ReadInt64());
            DateOpened = DateTime.FromBinary(reader.ReadInt64());

            Locked    = reader.ReadBoolean();
            Collected = reader.ReadBoolean();
            CanReply  = reader.ReadBoolean();
        }
Beispiel #2
0
        public bool Receive()
        {
            if (!Sent)
            {
                return(false);       //mail not sent yet
            }
            if (RecipientInfo == null)
            {
                RecipientInfo = Envir.GetCharacterInfo(RecipientIndex);

                if (RecipientInfo == null)
                {
                    return(false);
                }
            }

            RecipientInfo.Mail.Add(this); //add to players inbox

            if (RecipientInfo.Player != null)
            {
                RecipientInfo.Player.NewMail = true; //notify player of new mail  --check in player process
            }

            Envir.Mail.Remove(this); //remove from postbox

            return(true);
        }
Beispiel #3
0
        public void Drop(byte level)
        {
            if (level > Info.Drops.Length)
            {
                return;
            }
            if (Info.Drops[level - 1] == null)
            {
                return;
            }
            if (LinkedMonster == null)
            {
                return;
            }
            List <DragonInfo.DropInfo> droplist = new List <DragonInfo.DropInfo>(Info.Drops[level - 1]);

            for (int i = 0; i < droplist.Count; i++)
            {
                DragonInfo.DropInfo drop = droplist[i];

                int rate = (int)(drop.Chance / Settings.DropRate); if (rate < 1)
                {
                    rate = 1;
                }
                if (Envir.Random.Next(rate) != 0)
                {
                    continue;
                }

                if (drop.Gold > 0)
                {
                    int gold = Envir.Random.Next((int)(drop.Gold / 2), (int)(drop.Gold + drop.Gold / 2)); //Messy

                    if (gold <= 0)
                    {
                        continue;
                    }

                    if (!DropGold((uint)gold))
                    {
                        return;
                    }
                }
                else
                {
                    UserItem item = Envir.CreateDropItem(drop.Item);
                    if (item == null)
                    {
                        continue;
                    }
                    if (!DropItem(item))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #4
0
        public void Send()
        {
            if (Sent)
            {
                return;
            }

            Collected = true;

            if (Parcel)
            {
                if (Items.Count > 0 && Gold > 0)
                {
                    if (!Settings.MailAutoSendGold || !Settings.MailAutoSendItems)
                    {
                        Collected = false;
                    }
                }
                if (Items.Count > 0)
                {
                    if (!Settings.MailAutoSendItems)
                    {
                        Collected = false;
                    }
                }
                else
                {
                    if (!Settings.MailAutoSendGold)
                    {
                        Collected = false;
                    }
                }
            }

            if (RecipientInfo == null)
            {
                RecipientInfo = Envir.GetCharacterInfo(RecipientIndex);
            }

            RecipientInfo.Mail.Add(this); //add to players inbox

            if (RecipientInfo.Player != null)
            {
                RecipientInfo.Player.NewMail = true; //notify player of new mail  --check in player process
            }

            DateSent = Envir.Now;
        }
Beispiel #5
0
        private void SpawnMonsters()
        {
            var topLeftLocation = new Point(CurrentLocation.X - Info.EventSize, CurrentLocation.Y - Info.EventSize);

            foreach (var eventRespawn in Info.Respawns)
            {
                var respawnInfo = new RespawnInfo();

                var monster = Envir.GetMonsterInfo(eventRespawn.MonsterName);
                if (monster == null)
                {
                    SMain.EnqueueDebugging(string.Format("{0} Activating Event:{1} FAILED COULDN'T FIND MONSTER {2}", Map.Info.FileName, Info.EventName, eventRespawn.MonsterName));
                    return;
                }
                respawnInfo.Spread          = eventRespawn.MonsterCount;
                respawnInfo.Count           = eventRespawn.MonsterCount;
                respawnInfo.MonsterIndex    = monster.Index;
                respawnInfo.Delay           = 10000;
                respawnInfo.SaveRespawnTime = false;
                respawnInfo.RespawnIndex    = 0;
                respawnInfo.RespawnTicks    = 0;


                if (eventRespawn.SpreadY == 0 && eventRespawn.SpreadX == 0 && eventRespawn.MonsterCount == 1)
                {
                    respawnInfo.Location = CurrentLocation;
                }
                else
                {
                    respawnInfo.Location = new Point(topLeftLocation.X + eventRespawn.SpreadX * 2, topLeftLocation.Y + eventRespawn.SpreadY * 2);
                }

                MapRespawn mapRespawn = new MapRespawn(respawnInfo);

                RouteInfo route = new RouteInfo();
                route.Location = respawnInfo.Location;
                route.Delay    = 1000;
                mapRespawn.Route.Add(route);

                mapRespawn.Map = Map;
                mapRespawn.IsEventObjective = eventRespawn.IsObjective;
                mapRespawn.Event            = this;
                MapRespawns.Add(mapRespawn);
            }

            Map.Respawns.AddRange(MapRespawns);
        }
Beispiel #6
0
        private void SpawnMonstersForInvasion(List <EventRespawn> respawns)
        {
            var topLeftLocation = new Point(CurrentLocation.X - Info.EventSize, CurrentLocation.Y - Info.EventSize);

            foreach (var eventRespawn in respawns)
            {
                var monster = Envir.GetMonsterInfo(eventRespawn.MonsterName);
                if (monster == null)
                {
                    SMain.EnqueueDebugging(string.Format("{0} Event:{1} FAILED COULDN'T FIND MONSTER {2}", Map.Info.FileName, Info.EventName, eventRespawn.MonsterName));
                    continue;
                }

                var respawnInfo = new RespawnInfo()
                {
                    Spread       = eventRespawn.MonsterCount,
                    Count        = eventRespawn.MonsterCount,
                    MonsterIndex = monster.Index,
                    Delay        = ushort.MaxValue
                };

                if (eventRespawn.SpreadY == 0 && eventRespawn.SpreadX == 0)
                {
                    respawnInfo.Location = CurrentLocation;
                }
                else
                {
                    respawnInfo.Location = new Point(topLeftLocation.X + eventRespawn.SpreadX * 2, topLeftLocation.Y + eventRespawn.SpreadY * 2);
                }

                MapRespawn mapRespawn = new MapRespawn(respawnInfo);

                RouteInfo route = new RouteInfo()
                {
                    Location = respawnInfo.Location,
                    Delay    = 1000,
                };
                mapRespawn.Route.Add(route);

                mapRespawn.Map = Map;
                mapRespawn.IsEventObjective = eventRespawn.IsObjective;
                mapRespawn.Event            = this;
                MapRespawns.Add(mapRespawn);
            }

            Map.Respawns.AddRange(MapRespawns);
        }
Beispiel #7
0
        public bool Load()
        {
            try
            {
                MonsterInfo info = Envir.GetMonsterInfo(Info.MonsterName);
                if (info == null)
                {
                    MessageQueue.Enqueue("加载龙失败(错误怪物名): " + Info.MonsterName);
                    return(false);
                }
                LinkedMonster = MonsterObject.GetMonster(info);

                Map map = Envir.GetMapByNameAndInstance(Info.MapFileName);
                if (map == null)
                {
                    MessageQueue.Enqueue("加载龙失败(错误的地图名): " + Info.MapFileName);
                    return(false);
                }

                if (Info.Location.X > map.Width || Info.Location.Y > map.Height)
                {
                    MessageQueue.Enqueue("加载龙失败(错误地图XY): " + Info.MapFileName);
                    return(false);
                }

                if (LinkedMonster.Spawn(map, Info.Location))
                {
                    if (LinkedMonster is EvilMir)
                    {
                        EvilMir mob = (EvilMir)LinkedMonster;
                        if (mob != null)
                        {
                            mob.DragonLink = true;
                        }
                    }
                    MonsterInfo bodyinfo = Envir.GetMonsterInfo(Info.BodyName);
                    if (bodyinfo != null)
                    {
                        MonsterObject bodymob;
                        Point         spawnlocation = Point.Empty;
                        for (int i = 0; i <= BodyLocations.Length - 1; i++)
                        {
                            bodymob       = MonsterObject.GetMonster(bodyinfo);
                            spawnlocation = new Point(LinkedMonster.CurrentLocation.X + BodyLocations[i].X, LinkedMonster.CurrentLocation.Y + BodyLocations[i].Y);
                            if (bodymob != null)
                            {
                                bodymob.Spawn(LinkedMonster.CurrentMap, spawnlocation);
                            }
                        }
                    }

                    DropArea = new Rectangle(Info.DropAreaTop.X, Info.DropAreaTop.Y, Info.DropAreaBottom.X - Info.DropAreaTop.X, Info.DropAreaBottom.Y - Info.DropAreaTop.Y);
                    Loaded   = true;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MessageQueue.Enqueue(ex);
            }

            MessageQueue.Enqueue("加载龙失败");
            return(false);
        }
Beispiel #8
0
        public static void Start(Envir envir)
        {
            if (Path == string.Empty) return;

            EditEnvir = envir;

            if (EditEnvir == null) return;

            var lines = File.ReadAllLines(Path);

            _endIndex = EditEnvir.MapIndex; // Last map index number

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("[")) // Read map info
                {
                    lines[i] = System.Text.RegularExpressions.Regex.Replace(lines[i], @"\s+", " "); // Clear white-space

                    lines[i] = lines[i].Replace(" ;", ";"); // Remove space before semi-colon

                    // Trim comment at the end of the line
                    if (lines[i].Contains(';'))
                        lines[i] = lines[i].Substring(0, lines[i].IndexOf(";", System.StringComparison.Ordinal));

                    MapInfo newMapInfo = new MapInfo { Index = ++_endIndex };

                    var a = lines[i].Split(']'); // Split map info into [0] = MapFile MapName 0 || [1] = Attributes

                    string[] b = a[0].Split(' ');

                    newMapInfo.MapFile = b[0].TrimStart('['); // Assign MapFile from variable and trim leading '[' char
                    newMapInfo.MapName = b[1]; // Assign MapName from variable

                    List<string> mapAttributes = new List<string>(); // Group of all attributes associated with that map
                    mapAttributes.AddRange(a[1].Split(' '));

                    int nri = mapAttributes.FindIndex(x => x.StartsWith("NORECONNECT(".ToUpper())); // NORECONNECT() placement in list of parameters
                    int fi = mapAttributes.FindIndex(x => x.StartsWith("FIRE(".ToUpper())); // FIRE() placement in list of parameters
                    int li = mapAttributes.FindIndex(x => x.StartsWith("LIGHTNING(".ToUpper())); // LIGHTNING() placement in list of parameters
                    int lighti = mapAttributes.FindIndex(x => x.StartsWith("LIGHT(".ToUpper())); // LIGHT() placement in list of parameters
                    int mmi = mapAttributes.FindIndex(x => x.StartsWith("MINIMAP(".ToUpper())); // MINIMAP() placement in list of parameters
                    int bmi = mapAttributes.FindIndex(x => x.StartsWith("BIGMAP(".ToUpper())); // BIGMAP() placement in list of parameters
                    int mli = mapAttributes.FindIndex(x => x.StartsWith("MAPLIGHT(".ToUpper())); // MAPLIGHT() placement in list of parameters
                    int minei = mapAttributes.FindIndex(x => x.StartsWith("MINE(".ToUpper())); // MINE() placement in list of parameters
                    int musici = mapAttributes.FindIndex(x => x.StartsWith("MUSIC(".ToUpper()));
                    newMapInfo.NoTeleport = mapAttributes.Any(s => s.Contains("NOTELEPORT".ToUpper()));
                    newMapInfo.NoReconnect = mapAttributes.Any(x => x.StartsWith("NORECONNECT(".ToUpper()));
                    newMapInfo.NoRandom = mapAttributes.Any(s => s.Contains("NORANDOMMOVE".ToUpper()));
                    newMapInfo.NoEscape = mapAttributes.Any(s => s.Contains("NOESCAPE".ToUpper()));
                    newMapInfo.NoRecall = mapAttributes.Any(s => s.Contains("NORECALL".ToUpper()));
                    newMapInfo.NoDrug = mapAttributes.Any(s => s.Contains("NODRUG".ToUpper()));
                    newMapInfo.NoPositionMove = mapAttributes.Any(s => s.Contains("NOPOSITIONMOVE".ToUpper()));
                    newMapInfo.NoThrowItem = mapAttributes.Any(s => s.Contains("NOTHROWITEM".ToUpper()));
                    newMapInfo.NoPlayerDrop = mapAttributes.Any(s => s.Contains("NOPLAYERDROP".ToUpper()));
                    newMapInfo.NoMonsterDrop = mapAttributes.Any(s => s.Contains("NOMONSTERDROP".ToUpper()));
                    newMapInfo.NoNames = mapAttributes.Any(s => s.Contains("NONAMES".ToUpper()));
                    newMapInfo.NoFight = mapAttributes.Any(s => s.Contains("NOFIGHT".ToUpper()));
                    newMapInfo.Fight = mapAttributes.Any(s => s.Contains("FIGHT".ToUpper()));
                    newMapInfo.Fire = mapAttributes.Any(x => x.StartsWith("FIRE(".ToUpper()));
                    newMapInfo.Lightning = mapAttributes.Any(x => x.StartsWith("LIGHTNING(".ToUpper()));
                    newMapInfo.MiniMap = mapAttributes.Any(x => x.StartsWith("MINIMAP(".ToUpper()));
                    newMapInfo.BigMap = mapAttributes.Any(x => x.StartsWith("BIGMAP(".ToUpper()));
                    newMapInfo.Mine = mapAttributes.Any(s => s.Contains("MINE(".ToUpper()));
                    newMapInfo.MapLight = mapAttributes.Any(s => s.Contains("MAPLIGHT(".ToUpper()));
                    newMapInfo.Music = mapAttributes.Any(s => s.Contains("MUSIC(".ToUpper()));
                    newMapInfo.Light = LightSetting.Normal;


                    if (newMapInfo.NoReconnect == true) // If there is a NORECONNECT attribute get its MapFile
                        newMapInfo.ReconnectMap = (newMapInfo.ReconnectMap == string.Empty) ? "0" : mapAttributes[nri].TrimStart("NORECONNECT(".ToCharArray()).TrimEnd(')');
                    if (mli != -1) // If there is a MAPLIGHT attribute get its value
                        newMapInfo.MapLightValue = Convert.ToByte(mapAttributes[mli].TrimStart("MAPLIGHT(".ToCharArray()).TrimEnd(')'));

                    if (mapAttributes.Any(s => s.Contains("MINE1".ToUpper()))) // Mir Mine 1
                        newMapInfo.MineIndex = 1;
                    if (mapAttributes.Any(s => s.Contains("MINE2".ToUpper()))) // Mir Mine 2
                        newMapInfo.MineIndex = 2;
                    if (minei != -1) // If there is a MINE attribute get its value
                        newMapInfo.MineIndex = Convert.ToByte(mapAttributes[minei].TrimStart("MINE(".ToCharArray()).TrimEnd(')'));

                    if (newMapInfo.Fire == true) // If there is a FIRE attribute get its value
                        newMapInfo.FireDamage = Convert.ToInt16(mapAttributes[fi].TrimStart("FIRE(".ToCharArray()).TrimEnd(')'));
                    if (newMapInfo.Lightning == true) // If there is a LIGHTNING attribute get its value
                        newMapInfo.LightningDamage = Convert.ToInt16(mapAttributes[li].TrimStart("LIGHTNING(".ToCharArray()).TrimEnd(')'));

                    if (newMapInfo.MiniMap == true) // If there is a MINIMAP attribute get its value
                        newMapInfo.MiniMapNumber = Convert.ToUInt16(mapAttributes[mmi].TrimStart("MINIMAP(".ToCharArray()).TrimEnd(')'));
                    if (newMapInfo.BigMap == true) // If there is a BIGMAP attribute get its value
                        newMapInfo.BigMapNumber = Convert.ToUInt16(mapAttributes[bmi].TrimStart("BIGMAP(".ToCharArray()).TrimEnd(')'));

                    if (newMapInfo.Music == true)
                        newMapInfo.MusicNumber = Convert.ToUInt16(mapAttributes[musici].TrimStart("MUSIC(".ToCharArray()).TrimEnd(')'));

                    if (lighti != -1) // Check if there is a LIGHT attribute and get its value
                    {
                        switch (mapAttributes[lighti].TrimStart("LIGHT(".ToCharArray()).TrimEnd(')'))
                        {
                            case "Dawn":
                                newMapInfo.Light = LightSetting.Dawn;
                                break;
                            case "Day":
                                newMapInfo.Light = LightSetting.Day;
                                break;
                            case "Evening":
                                newMapInfo.Light = LightSetting.Evening;
                                break;
                            case "Night":
                                newMapInfo.Light = LightSetting.Night;
                                break;
                            case "Normal":
                                newMapInfo.Light = LightSetting.Normal;
                                break;
                            default:
                                newMapInfo.Light = LightSetting.Normal;
                                break;
                        }
                    }

                    // Check for light type
                    if (mapAttributes.Any(s => s.Contains("DAY".ToUpper()))) // DAY = Day
                        newMapInfo.Light = LightSetting.Day;
                    else if (mapAttributes.Any(s => s.Contains("DARK".ToUpper()))) // DARK = Night
                        newMapInfo.Light = LightSetting.Night;

                    MapInfo.Add(newMapInfo); // Add map to list
                }
            }

            for (int j = 0; j < MapInfo.Count; j++)
            {
                for (int k = 0; k < lines.Length; k++)
                {
                    try
                    {
                        if (lines[k].StartsWith(MapInfo[j].MapFile + " "))
                        {
                            MapMovements newmapMovements = new MapMovements();

                            lines[k] = lines[k].Replace('.', ','); // Replace point with comma
                            lines[k] = lines[k].Replace(":", ","); // Replace colon with comma
                            lines[k] = lines[k].Replace(", ", ","); // Remove space after comma
                            lines[k] = lines[k].Replace(" ,", ","); // Remove space before comma
                            lines[k] = System.Text.RegularExpressions.Regex.Replace(lines[k], @"\s+", " "); // Clear whitespace
                            lines[k] = lines[k].Replace(" ;", ";"); // Remove space before semi-colon

                            // Trim comment at the end of the line
                            if (lines[k].Contains(';'))
                                lines[k] = lines[k].Substring(0, lines[k].IndexOf(";", System.StringComparison.Ordinal));

                            var c = lines[k].Split(' ');

                            // START - Get values from line
                            if (c.Length == 7) // Every value has a space
                            {
                                c[1] = c[1] + "," + c[2];
                                c[2] = c[5] + "," + c[6];
                                c[3] = c[4];
                            }
                            else if (c.Length == 6) // One value has a space
                            {
                                if (c[2] == "->") // Space in to XY
                                {
                                    c[2] = c[4] + "," + c[5];
                                }
                                else if (c[3] == "->") // Space in from XY
                                {
                                    c[1] = c[1] + "," + c[2];
                                    c[2] = c[5];
                                    c[3] = c[4];
                                }
                            }
                            else if (c.Length == 5) // Proper format
                            {
                                c[2] = c[4];
                            }
                            else // Unreadable value count
                            {
                                continue;
                            }
                            // END - Get values from line

                            string[] d = c[1].Split(',');

                            string[] e = c[2].Split(',');


                            var toMapIndex = EditEnvir.MapInfoList.FindIndex(a => a.FileName == c[3]); //check existing maps for the connection info
                            var toMap = -1;

                            if (toMapIndex >= 0)
                            {
                                toMap = EditEnvir.MapInfoList[toMapIndex].Index; //get real index
                            }

                            if(toMap < 0)
                            {
                                toMapIndex = MapInfo.FindIndex(a => a.MapFile.ToString() == c[3]);

                                if(toMapIndex >= 0)
                                {
                                    toMap = MapInfo[toMapIndex].Index;
                                }
                            }

                            if (toMap < 0) continue;

                            newmapMovements.fromIndex = MapInfo[MapInfo.FindIndex(a => a.MapFile.ToString() == MapInfo[j].MapFile)].Index; // Check MapInfo for MapFile (mapInfo[j].mapFile) and get it's index number
                            newmapMovements.fromX = d[0];
                            newmapMovements.fromY = d[1];
                            newmapMovements.toMap = toMap;
                            newmapMovements.toX = e[0];
                            newmapMovements.toY = e[1];

                            MapMovements.Add(newmapMovements); // Add movements
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

            for (int j = 0; j < MapInfo.Count; j++)
            {
                for (int k = 0; k < lines.Length; k++)
                {
                    if (!lines[k].StartsWith("MINEZONE")) continue;
                    var line = lines[k].Split(' ');

                    try
                    {
                        if (line[1] == MapInfo[j].MapFile)
                        {
                          MineInfo newMineInfo = new MineInfo
                          {
                             MapIndex = MapInfo[j].Index,
                             MineIndex = Convert.ToInt16(line[3]),
                             Location = new Point(Convert.ToInt16(line[4]), Convert.ToInt16(line[5])),
                             Range = Convert.ToInt16(line[6])
                          };

                          MineInfo.Add(newMineInfo);
                        }
                    }
                    catch (Exception) { continue; }
                }
            }
        }