Example #1
0
 private static void LoadGameData()
 {
     Console.ForegroundColor = ConsoleColor.Yellow;
     Console.WriteLine("Loading Classes..."); modDatabase.LoadClasses();
     Console.WriteLine("Loading Maps..."); modDatabase.LoadMaps();
     Console.WriteLine("Creating Map Matrices...");
     for (int i = 1; i < Constants.MAX_MAPS; i++)
     {
         modPathfinding.CreatePathMatrix(i);
     }
     Console.WriteLine("Loading Items..."); S_Items.LoadItems();
     Console.WriteLine("Loading Npc's..."); modDatabase.LoadNpcs();
     Console.WriteLine("Loading Resources..."); S_Resources.LoadResources();
     Console.WriteLine("Loading Shops..."); modDatabase.LoadShops();
     Console.WriteLine("Loading Skills..."); modDatabase.LoadSkills();
     Console.WriteLine("Loading Animations..."); S_Animations.LoadAnimations();
     Console.WriteLine("Loading Quests..."); S_Quest.LoadQuests();
     Console.WriteLine("Loading House Configurations..."); S_Housing.LoadHouses();
     Console.WriteLine("Loading Switches..."); S_Events.LoadSwitches();
     Console.WriteLine("Loading Variables..."); S_Events.LoadVariables();
     Console.WriteLine("Spawning global events..."); S_EventLogic.SpawnAllMapGlobalEvents();
     Console.WriteLine("Loading projectiles..."); S_Projectiles.LoadProjectiles();
     Console.WriteLine("Loading Recipes..."); modCrafting.LoadRecipes();
     Console.WriteLine("Loading Pets..."); S_Pets.LoadPets();
     Console.ResetColor();
 }
Example #2
0
        internal static bool CanStartQuest(int index, int QuestNum)
        {
            bool CanStartQuest = false;
            bool flag          = QuestNum < 1 || QuestNum > 250;

            checked
            {
                if (!flag)
                {
                    bool flag2 = S_Quest.QuestInProgress(index, QuestNum);
                    if (!flag2)
                    {
                        bool flag3 = modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].PlayerQuest[QuestNum].Status == 0 || modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].PlayerQuest[QuestNum].Status == 3;
                        if (flag3)
                        {
                            int reqCount = S_Quest.Quest[QuestNum].ReqCount;
                            for (int i = 1; i <= reqCount; i++)
                            {
                                bool flag4 = S_Quest.Quest[QuestNum].Requirement[i] == 1;
                                if (flag4)
                                {
                                    bool flag5 = S_Quest.Quest[QuestNum].RequirementIndex[i] > 0 && S_Quest.Quest[QuestNum].RequirementIndex[i] <= 500;
                                    if (flag5)
                                    {
                                        bool flag6 = S_Players.HasItem(index, S_Quest.Quest[QuestNum].RequirementIndex[i]) == 0;
                                        if (flag6)
                                        {
                                            S_NetworkSend.PlayerMsg(index, "You need " + Types.Item[S_Quest.Quest[QuestNum].Requirement[2]].Name + " to take this quest!", 14);
                                            return(CanStartQuest);
                                        }
                                    }
                                }
                                bool flag7 = S_Quest.Quest[QuestNum].Requirement[i] == 2;
                                if (flag7)
                                {
                                    bool flag8 = S_Quest.Quest[QuestNum].RequirementIndex[i] > 0 && S_Quest.Quest[QuestNum].RequirementIndex[i] <= 250;
                                    if (flag8)
                                    {
                                        bool flag9 = modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].PlayerQuest[S_Quest.Quest[QuestNum].Requirement[2]].Status == 0 || modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].PlayerQuest[S_Quest.Quest[QuestNum].Requirement[2]].Status == 1;
                                        if (flag9)
                                        {
                                            S_NetworkSend.PlayerMsg(index, "You need to complete the " + S_Quest.Quest[S_Quest.Quest[QuestNum].Requirement[2]].Name.Trim() + " quest in order to take this quest!", 14);
                                            return(CanStartQuest);
                                        }
                                    }
                                }
                            }
                            CanStartQuest = true;
                        }
                    }
                }
                return(CanStartQuest);
            }
        }
Example #3
0
 internal static void ClearGameData()
 {
     Console.WriteLine("Clearing temp tile fields..."); modDatabase.ClearTempTiles();
     Console.WriteLine("Clearing Maps..."); modDatabase.ClearMaps();
     Console.WriteLine("Clearing Map Items..."); modDatabase.ClearMapItems();
     Console.WriteLine("Clearing Map Npc's..."); modDatabase.ClearAllMapNpcs();
     Console.WriteLine("Clearing Npc's..."); modDatabase.ClearNpcs();
     Console.WriteLine("Clearing Resources..."); S_Resources.ClearResources();
     Console.WriteLine("Clearing Items..."); S_Items.ClearItems();
     Console.WriteLine("Clearing Shops..."); modDatabase.ClearShops();
     Console.WriteLine("Clearing Skills..."); modDatabase.ClearSkills();
     Console.WriteLine("Clearing Animations..."); S_Animations.ClearAnimations();
     Console.WriteLine("Clearing Quests..."); S_Quest.ClearQuests();
     Console.WriteLine("Clearing map projectiles..."); S_Projectiles.ClearMapProjectiles();
     Console.WriteLine("Clearing projectiles..."); S_Projectiles.ClearProjectiles();
     Console.WriteLine("Clearing Recipes..."); modCrafting.ClearRecipes();
     Console.WriteLine("Clearing pets..."); S_Pets.ClearPets();
 }
Example #4
0
 private static void LoadGameData()
 {
     Console.WriteLine("Loading Classes..."); modDatabase.LoadClasses();
     Console.WriteLine("Loading Maps..."); modDatabase.LoadMaps();
     Console.WriteLine("Loading Items..."); S_Items.LoadItems();
     Console.WriteLine("Loading Npc's..."); modDatabase.LoadNpcs();
     Console.WriteLine("Loading Resources..."); S_Resources.LoadResources();
     Console.WriteLine("Loading Shops..."); modDatabase.LoadShops();
     Console.WriteLine("Loading Skills..."); modDatabase.LoadSkills();
     Console.WriteLine("Loading Animations..."); S_Animations.LoadAnimations();
     Console.WriteLine("Loading Quests..."); S_Quest.LoadQuests();
     Console.WriteLine("Loading House Configurations..."); S_Housing.LoadHouses();
     Console.WriteLine("Loading Switches..."); S_Events.LoadSwitches();
     Console.WriteLine("Loading Variables..."); S_Events.LoadVariables();
     Console.WriteLine("Spawning global events..."); S_EventLogic.SpawnAllMapGlobalEvents();
     Console.WriteLine("Loading projectiles..."); S_Projectiles.LoadProjectiles();
     Console.WriteLine("Loading Recipes..."); modCrafting.LoadRecipes();
     Console.WriteLine("Loading Pets..."); S_Pets.LoadPets();
 }
Example #5
0
        public static void InitServer()
        {
            int i;
            int F;
            int x;
            int time1;
            int time2;

            myStopWatch.Start();

            if (Debugger.IsAttached)
            {
                // Since there is a debugger attached,
                // assume we are running from the IDE
                S_Globals.Debugging = true;
            }
            else
            {
                // Assume we aren't running from the IDE
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += ErrorHandler;
            }

            Console.Title = "Orion+# Server";
            Console.SetWindowSize(120, 20);

            time1 = GetTimeMs();

            // Initialize the random-number generator
            VBMath.Randomize();

            // LOAD ENCRYPTION
            var fi = Application.StartupPath + @"\AsyncKeys.xml";

            if (!File.Exists(fi))
            {
                S_Globals.EKeyPair.GenerateKeys();
                S_Globals.EKeyPair.ExportKey(fi, true); // True exports private key too.
            }
            else
            {
                S_Globals.EKeyPair.ImportKey(fi);
            }
            // END LOAD ENCRYPTION

            modTypes.Map = new MapRec[601];

            modTypes.MapNpc = new MapDataRec[601];
            for (i = 0; i <= S_Instances.MAX_CACHED_MAPS; i++)
            {
                modTypes.MapNpc[i].Npc = new MapNpcRec[Constants.MAX_MAP_NPCS + 1];
                modTypes.Map[i].Npc    = new int[Constants.MAX_MAP_NPCS + 1];
            }

            // quests
            S_Quest.Quest = new QuestRec[251];
            S_Quest.ClearQuests();

            // event
            S_Events.Switches     = new string[501];
            S_Events.Variables    = new string[501];
            S_Events.TempEventMap = new GlobalEventsStruct[601];

            // Housing
            S_Housing.HouseConfig = new HouseRec[S_Housing.MAX_HOUSES + 1];

            for (i = 0; i <= S_Instances.MAX_CACHED_MAPS; i++)
            {
                for (x = 0; x <= Constants.MAX_MAP_NPCS; x++)
                {
                    modTypes.MapNpc[i].Npc[x].Vital = new int[(int)Enums.VitalType.Count + 1];
                }
            }

            modTypes.Bank = new BankRec[71];

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                modTypes.Bank[i].Item     = new PlayerInvRec[Constants.MAX_BANK + 1];
                modTypes.Bank[i].ItemRand = new RandInvRec[Constants.MAX_BANK + 1];
                for (x = 1; x <= Constants.MAX_BANK; x++)
                {
                    modTypes.Bank[i].ItemRand[x].Stat = new int[7];
                }
            }

            modTypes.Player = new PlayerRec[71];

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                // multi char
                modTypes.Player[i].Character = new CharacterRec[S_Constants.MAX_CHARS + 1];
                for (x = 1; x <= S_Constants.MAX_CHARS; x++)
                {
                    modTypes.Player[i].Character[x].Switches    = new byte[501];
                    modTypes.Player[i].Character[x].Variables   = new int[501];
                    modTypes.Player[i].Character[x].Vital       = new int[4];
                    modTypes.Player[i].Character[x].Stat        = new int[7];
                    modTypes.Player[i].Character[x].Equipment   = new int[7];
                    modTypes.Player[i].Character[x].Inv         = new PlayerInvRec[Constants.MAX_INV + 1];
                    modTypes.Player[i].Character[x].Skill       = new int[Constants.MAX_PLAYER_SKILLS + 1];
                    modTypes.Player[i].Character[x].PlayerQuest = new PlayerQuestRec[251];

                    modTypes.Player[i].Character[x].RandEquip = new RandInvRec[7];
                    modTypes.Player[i].Character[x].RandInv   = new RandInvRec[Constants.MAX_INV + 1];
                    for (var y = 1; y <= (int)Enums.EquipmentType.Count - 1; y++)
                    {
                        modTypes.Player[i].Character[x].RandEquip[y].Stat = new int[7];
                    }
                    for (int y = 1; y <= Constants.MAX_INV; y++)
                    {
                        modTypes.Player[i].Character[x].RandInv[y].Stat = new int[7];
                    }
                }
            }

            modTypes.TempPlayer = new TempPlayerRec[71];

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                modTypes.TempPlayer[i].SkillCd    = new int[Constants.MAX_PLAYER_SKILLS + 1];
                modTypes.TempPlayer[i].PetSkillCd = new int[5];
            }

            for (i = 1; i <= Constants.MAX_PLAYERS; i++)
            {
                modTypes.TempPlayer[i].TradeOffer = new PlayerInvRec[Constants.MAX_INV + 1];
            }

            S_AutoMap.LoadTilePrefab();

            Types.Classes = new ClassRec[S_Globals.Max_Classes + 1];
            var loopTo = S_Globals.Max_Classes;

            for (i = 0; i <= loopTo; i++)
            {
                Types.Classes[i].Stat       = new byte[7];
                Types.Classes[i].StartItem  = new int[6];
                Types.Classes[i].StartValue = new int[6];
            }

            for (i = 0; i <= Constants.MAX_ITEMS; i++)
            {
                Types.Item[i].Add_Stat        = new byte[7];
                Types.Item[i].Stat_Req        = new byte[7];
                Types.Item[i].FurnitureBlocks = new int[4, 4];
                Types.Item[i].FurnitureFringe = new int[4, 4];
            }
            Types.Npc[Constants.MAX_NPCS].Stat = new byte[7];

            Types.Shop[Constants.MAX_SHOPS].TradeItem = new TradeItemRec[Constants.MAX_TRADES + 1];

            Types.Animation[Constants.MAX_ANIMATIONS].Sprite    = new int[2];
            Types.Animation[Constants.MAX_ANIMATIONS].Frames    = new int[2];
            Types.Animation[Constants.MAX_ANIMATIONS].LoopCount = new int[2];
            Types.Animation[Constants.MAX_ANIMATIONS].LoopTime  = new int[2];

            S_Projectiles.MapProjectiles = new MapProjectileRec[601, 256];
            S_Projectiles.Projectiles    = new ProjectileRec[256];

            // parties
            S_Parties.ClearParties();

            // pets
            S_Pets.Pet = new PetRec[101];
            S_Pets.ClearPets();

            // Check if the directory is there, if its not make it
            CheckDir(Path.Combine(Application.StartupPath, "data"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "items"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "maps"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "npcs"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "shops"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "skills"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "accounts"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "resources"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "animations"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "logs"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "quests"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "recipes"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "pets"));
            CheckDir(Path.Combine(Application.StartupPath, "data", "projectiles"));

            // load options, set if they dont exist
            if (!File.Exists(Path.Combine(Application.StartupPath, "Data", "Config.xml")))
            {
                modTypes.Options.GameName = "Orion+#";
                modTypes.Options.Port     = 7001;
                modTypes.Options.Motd     = "Welcome to the Orion+# Engine";
                modTypes.Options.Website  = "http://ascensiongamedev.com/index.php";
                modTypes.Options.StartMap = 1;
                modTypes.Options.StartX   = 13;
                modTypes.Options.StartY   = 7;
                modDatabase.SaveOptions();
            }
            else
            {
                modDatabase.LoadOptions();
            }

            // Get that network READY SUN! ~ SpiceyWOlf
            S_NetworkConfig.InitNetwork();

            // Init all the player sockets
            Console.WriteLine("Initializing player array...");

            for (x = 1; x <= Constants.MAX_PLAYERS; x++)
            {
                modDatabase.ClearPlayer(x);
            }

            // Serves as a constructor
            ClearGameData();
            LoadGameData();
            Console.WriteLine("Spawning map items...");
            S_Items.SpawnAllMapsItems();
            Console.WriteLine("Spawning map npcs...");
            S_Npc.SpawnAllMapNpcs();

            // Check if the master charlist file exists for checking duplicate names, and if it doesnt make it
            if (!File.Exists(@"data\accounts\charlist.txt"))
            {
                F = FileSystem.FreeFile();
            }

            // resource system
            S_Resources.LoadSkillExp();

            modTime.InitTime();

            UpdateCaption();
            time2 = GetTimeMs();

            Console.Clear();
            Console.WriteLine("   ____       _                   _  _   ");
            Console.WriteLine(@"  / __ \     (_)             _  _| || |_ ");
            Console.WriteLine(" | |  | |_ __ _  ___  _ __ _| ||_  __  _|");
            Console.WriteLine(@" | |  | | '__| |/ _ \| '_ \_   _|| || |_ ");
            Console.WriteLine(@" | |__| | |  | | (_) | | | ||_||_  __  _|");
            Console.WriteLine(@"  \____/|_|  |_|\___/|_| |_|     |_||_|  ");

            Console.WriteLine("");

            Console.WriteLine("Initialization complete. Server loaded in " + (time2 - time1).ToString() + "ms.");
            Console.WriteLine("");
            Console.WriteLine("Use /help for the available commands.");

            MyIPAddress = S_NetworkConfig.GetIP();

            UpdateCaption();

            // reset shutdown value
            S_Globals.isShuttingDown = false;

            // Start listener now that everything is loaded
            S_NetworkConfig.Socket.StartListening(modTypes.Options.Port, 5, 1);

            // Starts the server loop
            modLoop.ServerLoop();
        }
        public static void CheckResource(int index, int x, int y)
        {
            int  Resource_num;
            byte ResourceType;
            int  Resource_index;
            int  rX;
            int  rY;
            int  Damage;

            if (modTypes.Map[S_Players.GetPlayerMap(index)].Tile[x, y].Type == (byte)Enums.TileType.Resource)
            {
                Resource_num   = 0;
                Resource_index = modTypes.Map[S_Players.GetPlayerMap(index)].Tile[x, y].Data1;
                ResourceType   = (byte)Types.Resource[Resource_index].ResourceType;
                var loopTo = ResourceCache[S_Players.GetPlayerMap(index)].ResourceCount;

                // Get the cache number
                for (var i = 0; i <= loopTo; i++)
                {
                    if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[i].X == x)
                    {
                        if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[i].Y == y)
                        {
                            Resource_num = i;
                        }
                    }
                }

                if (Resource_num > 0)
                {
                    if (S_Players.GetPlayerEquipment(index, Enums.EquipmentType.Weapon) > 0 || Types.Resource[Resource_index].ToolRequired == 0)
                    {
                        if (Types.Item[S_Players.GetPlayerEquipment(index, Enums.EquipmentType.Weapon)].Data3 == Types.Resource[Resource_index].ToolRequired)
                        {
                            // inv space?
                            if (Types.Resource[Resource_index].ItemReward > 0)
                            {
                                if (S_Players.FindOpenInvSlot(index, Types.Resource[Resource_index].ItemReward) == 0)
                                {
                                    S_NetworkSend.PlayerMsg(index, "You have no inventory space.", (int)Enums.ColorType.Yellow);
                                    return;
                                }
                            }

                            // required lvl?
                            if (Types.Resource[Resource_index].LvlRequired > GetPlayerGatherSkillLvl(index, ResourceType))
                            {
                                S_NetworkSend.PlayerMsg(index, "Your level is too low!", (int)Enums.ColorType.Yellow);
                                return;
                            }

                            // check if already cut down
                            if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].ResourceState == 0)
                            {
                                rX = ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].X;
                                rY = ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].Y;

                                if (Types.Resource[Resource_index].ToolRequired == 0)
                                {
                                    Damage = 1 * GetPlayerGatherSkillLvl(index, ResourceType);
                                }
                                else
                                {
                                    Damage = Types.Item[S_Players.GetPlayerEquipment(index, Enums.EquipmentType.Weapon)].Data2;
                                }

                                // check if damage is more than health
                                if (Damage > 0)
                                {
                                    // cut it down!
                                    if (ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].CurHealth - Damage <= 0)
                                    {
                                        ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].ResourceState = 1; // Cut
                                        ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].ResourceTimer = S_General.GetTimeMs();
                                        SendResourceCacheToMap(S_Players.GetPlayerMap(index), Resource_num);
                                        S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].SuccessMessage.Trim(), (int)Enums.ColorType.BrightGreen, 1, (S_Players.GetPlayerX(index) * 32), (S_Players.GetPlayerY(index) * 32));
                                        S_Players.GiveInvItem(index, Types.Resource[Resource_index].ItemReward, 1);
                                        S_Animations.SendAnimation(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].Animation, rX, rY);
                                        SetPlayerGatherSkillExp(index, ResourceType, GetPlayerGatherSkillExp(index, ResourceType) + Types.Resource[Resource_index].ExpReward);
                                        // send msg
                                        S_NetworkSend.PlayerMsg(index, string.Format("Your {0} has earned {1} experience. ({2}/{3})", GetResourceSkillName((Enums.ResourceSkills)ResourceType), Types.Resource[Resource_index].ExpReward, GetPlayerGatherSkillExp(index, ResourceType), GetPlayerGatherSkillMaxExp(index, ResourceType)), (int)Enums.ColorType.BrightGreen);
                                        S_NetworkSend.SendPlayerData(index);

                                        CheckResourceLevelUp(index, ResourceType);
                                    }
                                    else
                                    {
                                        // just do the damage
                                        ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].CurHealth = (byte)(ResourceCache[S_Players.GetPlayerMap(index)].ResourceData[Resource_num].CurHealth - Damage);
                                        S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), "-" + Damage, (int)Enums.ColorType.BrightRed, 1, (rX * 32), (rY * 32));
                                        S_Animations.SendAnimation(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].Animation, rX, rY);
                                    }
                                    S_Quest.CheckTasks(index, (int)Enums.QuestType.Gather, Resource_index);
                                }
                                else
                                {
                                    // too weak
                                    S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), "Miss!", (int)Enums.ColorType.BrightRed, 1, (rX * 32), (rY * 32));
                                }
                            }
                            else
                            {
                                S_NetworkSend.SendActionMsg(S_Players.GetPlayerMap(index), Types.Resource[Resource_index].EmptyMessage.Trim(), (int)Enums.ColorType.BrightRed, 1, (S_Players.GetPlayerX(index) * 32), (S_Players.GetPlayerY(index) * 32));
                            }
                        }
                        else
                        {
                            S_NetworkSend.PlayerMsg(index, "You have the wrong type of tool equiped.", (int)Enums.ColorType.Yellow);
                        }
                    }
                    else
                    {
                        S_NetworkSend.PlayerMsg(index, "You need a tool to gather this resource.", (int)Enums.ColorType.Yellow);
                    }
                }
            }
        }