Ejemplo n.º 1
0
        public void Spawn()
        {
            NPCInfo npcInfo = new NPCInfo
            {
                Name     = Info.Name,
                FileName = Info.FileName,
                Location = Info.Location,
                Image    = 1000
            };

            if (Conquest.Guild != null)
            {
                Guild          = Conquest.Guild;
                npcInfo.Image  = Guild.FlagImage;
                npcInfo.Colour = Guild.FlagColour;
            }

            Flag = new NPCObject(npcInfo)
            {
                CurrentMap = Conquest.ConquestMap
            };

            Flag.CurrentMap.AddObject(Flag);

            Flag.Spawned();
        }
Ejemplo n.º 2
0
        public virtual void Add(HumanObject player)
        {
            if (player.Race != ObjectType.Player)
            {
                return;
            }

            if (Race == ObjectType.Merchant)
            {
                NPCObject npc = (NPCObject)this;
                npc.CheckVisible((PlayerObject)player, true);
                return;
            }

            player.Enqueue(GetInfo());

            //if (Race == ObjectType.Player)
            //{
            //    PlayerObject me = (PlayerObject)this;
            //    player.Enqueue(me.GetInfoEx(player));
            //}
            //else
            //{
            //    player.Enqueue(GetInfo());
            //}
        }
Ejemplo n.º 3
0
        private void ParseSpeech(IList<string> lines)
        {
            var loadedNPC = NPCObject.Get(LoadedObjectID);

            if (loadedNPC == null)
            {
                return;
            }

            for (int i = 0; i < lines.Count; i++)
            {
                if (!lines[i].ToUpper().StartsWith(SpeechKey)) continue;

                while (++i < lines.Count)
                {
                    if (String.IsNullOrEmpty(lines[i])) continue;

                    var parts = lines[i].Split(' ');

                    if (parts.Length < 2 || !int.TryParse(parts[0], out int weight)) return;

                    loadedNPC.Speech.Add(new NPCSpeech { Weight = weight, Message = lines[i].Substring(parts[0].Length + 1) });
                }
            }
        }
Ejemplo n.º 4
0
        private void ParseQuests(IList <string> lines)
        {
            for (int i = 0; i < lines.Count; i++)
            {
                if (!lines[i].ToUpper().StartsWith(QuestKey))
                {
                    continue;
                }

                var loadedNPC = NPCObject.Get(LoadedObjectID);

                if (loadedNPC == null)
                {
                    return;
                }

                while (++i < lines.Count)
                {
                    if (lines[i].StartsWith("["))
                    {
                        return;
                    }
                    if (String.IsNullOrEmpty(lines[i]))
                    {
                        continue;
                    }

                    int.TryParse(lines[i], out int index);

                    if (index == 0)
                    {
                        continue;
                    }

                    QuestInfo info = Envir.GetQuestInfo(Math.Abs(index));

                    if (info == null)
                    {
                        return;
                    }

                    if (index > 0)
                    {
                        info.NpcIndex = LoadedObjectID;
                    }
                    else
                    {
                        info.FinishNpcIndex = LoadedObjectID;
                    }

                    if (loadedNPC.Quests.All(x => x != info))
                    {
                        loadedNPC.Quests.Add(info);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void LoadGoods()
        {
            var loadedNPC = NPCObject.Get(LoadedObjectID);

            if (loadedNPC != null)
            {
                string path = Path.Combine(Settings.GoodsPath, loadedNPC.Info.Index.ToString() + ".msd");

                if (!File.Exists(path))
                {
                    return;
                }

                using (FileStream stream = File.OpenRead(path))
                {
                    using (BinaryReader reader = new BinaryReader(stream))
                    {
                        int version       = reader.ReadInt32();
                        int count         = version;
                        int customversion = Envir.LoadCustomVersion;
                        if (version == 9999)//the only real way to tell if the file was made before or after version code got added: assuming nobody had a config option to save more then 10000 sold items
                        {
                            version       = reader.ReadInt32();
                            customversion = reader.ReadInt32();
                            count         = reader.ReadInt32();
                        }
                        else
                        {
                            version = Envir.LoadVersion;
                        }

                        for (int k = 0; k < count; k++)
                        {
                            UserItem item = new UserItem(reader, version, customversion);
                            if (Envir.BindItem(item))
                            {
                                loadedNPC.UsedGoods.Add(item);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void StartEnvir()
        {
            Players.Clear();
            StartPoints.Clear();
            StartItems.Clear();
            MapList.Clear();

            CustomCommands.Clear();

            LoadDB();

            for (int i = 0; i < MapInfoList.Count; i++)
                MapInfoList[i].CreateMap();
            SMain.Enqueue(string.Format("{0} Maps Loaded.", MapInfoList.Count));

            for (int i = 0; i < ItemInfoList.Count; i++)
                if (ItemInfoList[i].StartItem)
                    StartItems.Add(ItemInfoList[i]);

            for (int i = 0; i < MonsterInfoList.Count; i++)
                MonsterInfoList[i].LoadDrops();

            LoadFishingDrops();
            LoadAwakeningMaterials();
            LoadStrongBoxDrops();
            LoadBlackStoneDrops();
            SMain.Enqueue("Drops Loaded.");

            if (DragonInfo.Enabled)
            {
                DragonSystem = new Dragon(DragonInfo);
                if (DragonSystem != null)
                {
                    if (DragonSystem.Load()) DragonSystem.Info.LoadDrops();
                }

                SMain.Enqueue("Dragon Loaded.");
            }

            DefaultNPC = new NPCObject(new NPCInfo() { Name = "DefaultNPC", FileName = Settings.DefaultNPCFilename, IsDefault = true });

            SMain.Enqueue("Envir Started.");
        }
Ejemplo n.º 7
0
        public void Buy(PlayerObject player, ulong index, uint count)
        {
            UserItem goods = null;

            for (int i = 0; i < Goods.Count; i++)
            {
                if (Goods[i].UniqueID != index)
                {
                    continue;
                }
                goods = Goods[i];
                break;
            }

            bool isUsed    = false;
            bool isBuyBack = false;

            var callingNPC = NPCObject.Get(player.NPCObjectID);

            if (callingNPC != null)
            {
                if (goods == null)
                {
                    for (int i = 0; i < callingNPC.UsedGoods.Count; i++)
                    {
                        if (callingNPC.UsedGoods[i].UniqueID != index)
                        {
                            continue;
                        }
                        goods  = callingNPC.UsedGoods[i];
                        isUsed = true;
                        break;
                    }
                }

                if (goods == null)
                {
                    if (!callingNPC.BuyBack.ContainsKey(player.Name))
                    {
                        callingNPC.BuyBack[player.Name] = new List <UserItem>();
                    }
                    for (int i = 0; i < callingNPC.BuyBack[player.Name].Count; i++)
                    {
                        if (callingNPC.BuyBack[player.Name][i].UniqueID != index)
                        {
                            continue;
                        }
                        goods     = callingNPC.BuyBack[player.Name][i];
                        isBuyBack = true;
                        break;
                    }
                }
            }

            if (goods == null || count == 0 || count > goods.Info.StackSize)
            {
                return;
            }

            if (isBuyBack && count > goods.Count)
            {
                count = goods.Count;
            }
            else
            {
                goods.Count = count;
            }

            uint cost = goods.Price();

            cost = (uint)(cost * PriceRate(player));
            uint baseCost = (uint)(goods.Price() * PriceRate(player, true));

            if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
            {
                if (cost > player.Info.PearlCount)
                {
                    return;
                }
            }
            else if (cost > player.Account.Gold)
            {
                return;
            }

            UserItem item = (isBuyBack || isUsed) ? goods : Envir.CreateFreshItem(goods.Info);

            item.Count = goods.Count;

            if (!player.CanGainItem(item))
            {
                return;
            }

            if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
            {
                player.Info.PearlCount -= (int)cost;
            }
            else
            {
                player.Account.Gold -= cost;
                player.Enqueue(new S.LoseGold {
                    Gold = cost
                });

                if (callingNPC != null && callingNPC.Conq != null)
                {
                    callingNPC.Conq.GoldStorage += (cost - baseCost);
                }
            }
            player.GainItem(item);

            if (isUsed)
            {
                callingNPC.UsedGoods.Remove(goods); //If used or buyback will destroy whole stack instead of reducing to remaining quantity

                List <UserItem> newGoodsList = new List <UserItem>();
                newGoodsList.AddRange(Goods);
                newGoodsList.AddRange(callingNPC.UsedGoods);

                callingNPC.NeedSave = true;

                player.Enqueue(new S.NPCGoods {
                    List = newGoodsList, Rate = PriceRate(player)
                });
            }

            if (isBuyBack)
            {
                callingNPC.BuyBack[player.Name].Remove(goods); //If used or buyback will destroy whole stack instead of reducing to remaining quantity
                player.Enqueue(new S.NPCGoods {
                    List = callingNPC.BuyBack[player.Name], Rate = PriceRate(player)
                });
            }
        }
Ejemplo n.º 8
0
        private void ProcessSpecial(PlayerObject player, NPCPage page)
        {
            List <UserItem> allGoods = new List <UserItem>();

            switch (page.Key.ToUpper())
            {
            case BuyKey:
                for (int i = 0; i < Goods.Count; i++)
                {
                    player.CheckItem(Goods[i]);
                }

                player.Enqueue(new S.NPCGoods {
                    List = Goods, Rate = PriceRate(player), Type = PanelType.Buy
                });
                break;

            case SellKey:
                player.Enqueue(new S.NPCSell());
                break;

            case BuySellKey:
                for (int i = 0; i < Goods.Count; i++)
                {
                    player.CheckItem(Goods[i]);
                }

                player.Enqueue(new S.NPCGoods {
                    List = Goods, Rate = PriceRate(player), Type = PanelType.Buy
                });
                player.Enqueue(new S.NPCSell());
                break;

            case RepairKey:
                player.Enqueue(new S.NPCRepair {
                    Rate = PriceRate(player)
                });
                break;

            case SRepairKey:
                player.Enqueue(new S.NPCSRepair {
                    Rate = PriceRate(player)
                });
                break;

            case CraftKey:
                for (int i = 0; i < CraftGoods.Count; i++)
                {
                    player.CheckItemInfo(CraftGoods[i].Item.Info);
                }

                player.Enqueue(new S.NPCGoods {
                    List = (from x in CraftGoods where x.CanCraft(player) select x.Item).ToList(), Rate = PriceRate(player), Type = PanelType.Craft
                });
                break;

            case RefineKey:
                if (player.Info.CurrentRefine != null)
                {
                    player.ReceiveChat("You're already refining an item.", ChatType.System);
                    player.Enqueue(new S.NPCRefine {
                        Rate = (Settings.RefineCost), Refining = true
                    });
                    break;
                }
                else
                {
                    player.Enqueue(new S.NPCRefine {
                        Rate = (Settings.RefineCost), Refining = false
                    });
                }
                break;

            case RefineCheckKey:
                player.Enqueue(new S.NPCCheckRefine());
                break;

            case RefineCollectKey:
                player.CollectRefine();
                break;

            case ReplaceWedRingKey:
                player.Enqueue(new S.NPCReplaceWedRing {
                    Rate = Settings.ReplaceWedRingCost
                });
                break;

            case StorageKey:
                player.SendStorage();
                player.Enqueue(new S.NPCStorage());
                break;

            case BuyBackKey:
            {
                var callingNPC = NPCObject.Get(player.NPCObjectID);

                if (callingNPC != null)
                {
                    if (!callingNPC.BuyBack.ContainsKey(player.Name))
                    {
                        callingNPC.BuyBack[player.Name] = new List <UserItem>();
                    }

                    for (int i = 0; i < callingNPC.BuyBack[player.Name].Count; i++)
                    {
                        player.CheckItem(callingNPC.BuyBack[player.Name][i]);
                    }

                    player.Enqueue(new S.NPCGoods {
                            List = callingNPC.BuyBack[player.Name], Rate = PriceRate(player), Type = PanelType.Buy
                        });
                }
            }
            break;

            case BuyUsedKey:
            {
                var callingNPC = NPCObject.Get(player.NPCObjectID);

                if (callingNPC != null)
                {
                    for (int i = 0; i < callingNPC.UsedGoods.Count; i++)
                    {
                        player.CheckItem(callingNPC.UsedGoods[i]);
                    }

                    player.Enqueue(new S.NPCGoods {
                            List = callingNPC.UsedGoods, Rate = PriceRate(player), Type = PanelType.Buy
                        });
                }
            }
            break;

            case ConsignKey:
                player.Enqueue(new S.NPCConsign());
                break;

            case MarketKey:
                player.UserMatch = false;
                player.GetMarket(string.Empty, ItemType.Nothing);
                break;

            case GuildCreateKey:
                if (player.Info.Level < Settings.Guild_RequiredLevel)
                {
                    player.ReceiveChat(String.Format("You have to be at least level {0} to create a guild.", Settings.Guild_RequiredLevel), ChatType.System);
                }
                else if (player.MyGuild == null)
                {
                    player.CanCreateGuild = true;
                    player.Enqueue(new S.GuildNameRequest());
                }
                else
                {
                    player.ReceiveChat("You are already part of a guild.", ChatType.System);
                }
                break;

            case RequestWarKey:
                if (player.MyGuild != null)
                {
                    if (player.MyGuildRank != player.MyGuild.Ranks[0])
                    {
                        player.ReceiveChat("You must be the leader to request a war.", ChatType.System);
                        return;
                    }
                    player.Enqueue(new S.GuildRequestWar());
                }
                else
                {
                    player.ReceiveChat(GameLanguage.NotInGuild, ChatType.System);
                }
                break;

            case SendParcelKey:
                player.Enqueue(new S.MailSendRequest());
                break;

            case CollectParcelKey:

                sbyte result = 0;

                if (player.GetMailAwaitingCollectionAmount() < 1)
                {
                    result = -1;
                }
                else
                {
                    foreach (var mail in player.Info.Mail)
                    {
                        if (mail.Parcel)
                        {
                            mail.Collected = true;
                        }
                    }
                }
                player.Enqueue(new S.ParcelCollected {
                    Result = result
                });
                player.GetMail();
                break;

            case AwakeningKey:
                player.Enqueue(new S.NPCAwakening());
                break;

            case DisassembleKey:
                player.Enqueue(new S.NPCDisassemble());
                break;

            case DowngradeKey:
                player.Enqueue(new S.NPCDowngrade());
                break;

            case ResetKey:
                player.Enqueue(new S.NPCReset());
                break;

            case PearlBuyKey:
                for (int i = 0; i < Goods.Count; i++)
                {
                    player.CheckItem(Goods[i]);
                }

                player.Enqueue(new S.NPCPearlGoods {
                    List = Goods, Rate = PriceRate(player)
                });
                break;
            }
        }