Ejemplo n.º 1
0
        public void SnapToPosition(short posX, short posZ)
        {
            StatsContainer container = GetStatsContainer();

            container.SetStat(StatType.POS_X, (short)posX);
            container.SetStat(StatType.POS_Z, (short)posZ);

            foreach (var item in ServerManager.Instance.CharactersManager.GetClientsInRange(Position, 50))
            {
                Server.Instance.SendData(item.Value.ip, new SnapPositionPacket(this));
            }
        }
Ejemplo n.º 2
0
        public CharactersManager()
        {
            DataTable mobsProtoTable = DatabaseManager.ReturnQuery("SELECT * FROM mobs_proto");

            for (int i = 0; i < mobsProtoTable.Rows.Count; i++)
            {
                DataRow row = mobsProtoTable.Rows[i];

                MobData data = new MobData()
                {
                    baseId    = (int)row["id"],
                    name      = (string)row["name"],
                    level     = (sbyte)row["lvl"],
                    health    = (int)row["health"],
                    expReward = (int)row["exp_reward"],
                    onClick   = (ClickType)(sbyte)row["on_click"],
                };

                mobsDataList.Add(data.baseId, data);
            }

            DataTable mobsTable = DatabaseManager.ReturnQuery("SELECT * FROM mobs");

            for (int i = 0; i < mobsTable.Rows.Count; i++)
            {
                DataRow row = mobsTable.Rows[i];

                int id = lastId++;
                Mob x  = CharactersManager.CreateMob(id);
                x.BaseId = (int)row["base_id"];
                MobData data = mobsDataList[x.BaseId];
                x.OnClick = data.onClick;

                StatsContainer stats = x.GetStatsContainer();
                stats.SetStat(StatType.NAME, (string)data.name);
                stats.SetStat(StatType.LEVEL, (short)data.level);
                stats.SetStat(StatType.HEALTH, (int)data.health);
                stats.SetStat(StatType.MAX_HEALTH, (int)data.health);
                stats.SetStat(StatType.POS_X, (short)row["pos_x"]);
                stats.SetStat(StatType.POS_Z, (short)row["pos_z"]);
                stats.SetStat(StatType.ROTATION, (short)row["rotation"]);
                x.SetSpawnPosition((short)row["pos_x"], (short)row["pos_z"]);

                AddCharacter(x);

                x.Init();
            }
        }
Ejemplo n.º 3
0
        public void DealDamage(Character character, Character target, AttackData attack)
        {
            StatsContainer targetContainer = target.GetStatsContainer();

            if (target is Mob)
            {
                targetContainer.SetStat(StatType.TARGET_ID, (int)character.Id);
                target.SelectionState = SelectionState.ATTACK;
            }

            int health = (int)targetContainer.GetStat(StatType.HEALTH).value;

            targetContainer.SetStat(StatType.HEALTH, health - attack.damage);

            foreach (var item in charactersManager.GetClientsInRange(character.Position, 50))
            {
                Server.Instance.SendData(item.Value.ip, new DamageInfoPacket(attack));
            }

            if (target.IsDead)
            {
                if (target is Player)
                {
                    target.GetStatsContainer().SetStat(StatType.HEALTH, (int)30);

                    short posX = (short)KingdomsManager.kingdoms[(byte)target.GetStat(StatType.KINGDOM)].spawnPoint.X;
                    short posZ = (short)KingdomsManager.kingdoms[(byte)target.GetStat(StatType.KINGDOM)].spawnPoint.Z;
                    target.SnapToPosition((short)posX, (short)posZ);
                }
                else
                {
                    ServerManager.Instance.CharactersManager.DespawnCharacter(target);
                }

                character.SelectionState = SelectionState.SELECTION;
                target.SelectionState    = SelectionState.SELECTION;

                if (character is Player)
                {
                    StatsContainer killerContainer = character.GetStatsContainer();
                    int            exp             = (int)killerContainer.GetStat(StatType.EXPERIENCE).value;
                    killerContainer.SetStat(StatType.EXPERIENCE, exp + 25);

                    if ((int)killerContainer.GetStat(StatType.EXPERIENCE).value >= 100)
                    {
                        killerContainer.SetStat(StatType.EXPERIENCE, 0);

                        short level = (short)killerContainer.GetStat(StatType.LEVEL).value;
                        killerContainer.SetStat(StatType.LEVEL, (short)(level + 1));
                    }

                    int goldReward = new Random().Next(20, 100);
                    character.AddStatInt(StatType.GOLD, goldReward);

                    int dropOrNot = new Random().Next(0, 4);

                    ItemsContainer inventory = character.GetItemsContainer(ItemsContainerId.INVENTORY);
                    if (inventory != null && dropOrNot == 0)
                    {
                        int freeSlot = inventory.GetFreeSlot();
                        if (freeSlot != -1)
                        {
                            inventory.AddItem(freeSlot, ServerManager.Instance.ItemsManager.CreateItemData(new ItemData()
                            {
                                baseId = new Random().Next(1, 8),
                            }));
                        }
                    }

                    ServerManager.Instance.QuestsManager.ExecuteEventsForAll(QuestEvent.MONSTER_DEFEAT, character.Id, target.BaseId);
                }

                if (character is Mob)
                {
                    Mob m = character as Mob;
                    m.SnapToPosition(m.StartPosX, m.StartPosZ);
                }
            }
        }