Esempio n. 1
0
        public void AddPlayer(Connection client, CharacterInfo ci)
        {
            if (!_players.ContainsKey(ci.ID))
            {
                ci.WorldID = _worldIDs++;

                // Send NPC info to player
                foreach (NPC npc in _npcs.Values)
                {
                    client.SendPacket(new NPCInfoPacket(npc));
                }

                // Send Monster info to player
                foreach (Monster m in _monsters.Values)
                {
                    client.SendPacket(new NPCInfoPacket(m));
                }

                // Send player character info to all other players
                if (_players.Count > 0)
                {
                    AddOtherPlayerPacket theNewGuy = new AddOtherPlayerPacket(ci);
                    foreach (Connection pc in _players.Values)
                    {
                        // Tell the other player about the new guy
                        pc.SendPacket(theNewGuy);

                        // Tell the new guy about this player
                        client.SendPacket(new AddOtherPlayerPacket(pc.Character));
                    }
                }
            }

            _players[ci.ID] = client;
        }
Esempio n. 2
0
        public string ClearItem(Connection client, byte slot)
        {
            // Change the data in memory
            _slots[slot] = 0;

            // Tell the client
            client.SendPacket(new ClearToolbarLink(slot));

            // Save in the database
            string sql = string.Format("UPDATE characters_toolbar SET slot_{0}=0 WHERE character_id={1};", slot, client.Character.ID);
            return sql;
        }
Esempio n. 3
0
        public void SendToClient(Connection client, bool showNext = true)
        {
            // Send the icon packet
            client.SendPacket(new WindowSettingsPacket_NPCIcon(_icon));

            // Send the text packet
            client.SendPacket(new WindowSettingsPacket_NPCDialog(_staticText, _text, showNext));
        }
Esempio n. 4
0
        public void GiveLoot(Connection client)
        {
            int exp = Program.Server.Rand.Next(_template.ExpMin, _template.ExpMax);
            int gold = Program.Server.Rand.Next(_template.GoldMin, _template.GoldMax);
            uint? lootTemplate = _template.LootTable.Generate();

            bool hvUpdate = false;
            if (exp > 0)
            {
                client.Character.GainExp(client, exp);
                hvUpdate = true;
            }
            if (gold > 0)
            {
                client.Character.GainGold(gold);
                client.SendPacket(new GoldLootPacket(client.Character.Gold, ID));
                hvUpdate = true;
            }
            if (lootTemplate != null)
            {
                Program.Server.TaskProcessor.AddTask(new Task(Task.TaskType.GiveItem, client, new GiveItemArgs(lootTemplate.Value, GiveItemArgs.TheReason.Loot, ID)));
            }

            if( hvUpdate )
                Program.Server.TaskProcessor.AddDBQuery(client.Character.HVString, null, false);
        }
Esempio n. 5
0
        public ItemError Use(Connection c)
        {
            ItemError err = ItemError.None;

            if (c.Character.CanUseItemNow(this))
            {
                switch (_template.ItemFunction)
                {
                    case ItemTemplate.ItemUseFunction.GainHealth:
                        if (c.Character.CurHP < c.Character.MaxHP)
                        {
                            _durability--;

                            // Adjust character health
                            c.Character.TakeDamage(-_template.ItemFunctionParam);

                            // Send health change to client
                            c.SendPacket(new HealthChangePacket(c.Character.CurHP));
                        }
                        else
                            err = ItemError.UnableToUseItem;
                        break;
                    default:
                    case ItemTemplate.ItemUseFunction.None:
                        break;
                }
            }
            else
                err = ItemError.YouCanUseItAfterTheCooldownTimeRunsOut;
            return err;
        }
Esempio n. 6
0
        public void ProcessMoveRequest(Connection client, CharacterPositionClass mtp)
        {
            // Check to see if we hit any npcs
            foreach (NPC npc in _npcs.Values)
            {
                if (npc.CellIndex == mtp.CellIndex)
                {
                    // Hit this npc - Check distance
                    Vector target = Utils.DecodeCellIndex(_mapID, mtp.CellIndex);
                    Vector start = Utils.DecodeCellIndex(_mapID, client.Character.CellIndex);
                    Vector toTarget = target - start;
                    double distSquared = toTarget.LengthSquared;
                    if (distSquared > 13)
                    {
                        // Out of range, just move there
                        client.SendPacket(new PlayerMovePacket(mtp.CellIndex, client.Character.MoveSpeed));
                    }
                    else
                    {
                        // Talk to NPC
                        npc.DoDialog(client);
                    }

                    // no matter what, we are done here
                    return;
                }
            }

            // Check to see if we hit monsters

            // Check to see if we hit other players

            // Just move
            client.SendPacket(new PlayerMovePacket(mtp.CellIndex, client.Character.MoveSpeed));
        }
Esempio n. 7
0
        public void PlayerAttackMonster(Connection client, AttackTargetRequest atr)
        {
            if (!_monsters.ContainsKey(atr.TargetID))
            {
                LogInterface.Log(string.Format("Character({0}) attacking non existant monster {1} on map {2}", client.Character.ID, atr.TargetID, client.Character.MapID), LogInterface.LogMessageType.Game);
                client.SendPacket(new SeePlayerAttack(atr.TargetID, 0, client.Character, atr, 6));        // Wrong target
            }
            else
            {
                Monster m = _monsters[atr.TargetID];

                client.Character.AttackTarget(m, atr);

                SeePlayerAttack pkt = new SeePlayerAttack(m.ID, m.CurHP, client.Character, atr);
                foreach( Connection c in _players.Values )
                    c.SendPacket(pkt);

                if (m.Dead)
                {
                    // Do loot!
                    m.GiveLoot(client);
                }
            }
        }
Esempio n. 8
0
        public void DoDialog(Connection client)
        {
            // Is the player working for me?
            Quest playerActiveQuest = client.Character.GetActiveQuestForNPC(_id);
            if (playerActiveQuest != null)
            {
                client.SetCurrentQuest(_id, playerActiveQuest.QuestID, 0);
                byte step = client.Character.GetQuestStep(playerActiveQuest.QuestID);
                QuestLine ql = playerActiveQuest.GetStep(step).GetLine(0);
                ql.SendToClient(client);
                client.SendPacket(new NPCDialogPacket(_gameID));
                return;
            }

            // Do I have something for the player?
            foreach (Quest q in _quests.Values)
            {
                if (!client.Character.HasActiveQuest(q.QuestID) && !client.Character.HasCompletedQuest(q.QuestID))
                {
                    if (q.PlayerMeetsRequirements(client.Character))
                    {
                        client.Character.ReceiveQuest(q);
                        client.SetCurrentQuest(_id, q.QuestID, 0);
                        QuestStep qs = q.GetStep(0);
                        qs.Activate(client);
                        QuestLine ql = qs.GetLine(0);
                        ql.SendToClient(client);
                        client.SendPacket(new NPCDialogPacket(_gameID));
                    }
                }
            }

            /*
            // Am I selling something?
            if (IsMerchant)
            {
                // Show sell dialog
            }

            // Just say hello
            if (_defaultText != null)
            {
                client.SendPacket(new NPCDialogPacket(_defaultText, _defaultIcon));
            }
            */
        }
Esempio n. 9
0
        public string SetItem(Connection client, ToolbarItemSetRequest tbr)
        {
            // Change the data in memory
            _slots[tbr.Slot] = tbr.TargetID | (tbr.Type == ToolbarItemSetRequest.TargetType.Skill ? 0x80000000 : 0);

            // Tell the client we accept
            client.SendPacket(new SetToolbarLink(tbr.TargetID, tbr.Type, tbr.Slot));

            // Save it in the database
            string sql = string.Format("UPDATE characters_toolbar SET slot_{0}={1} WHERE character_id={2};", tbr.Slot, _slots[tbr.Slot], client.Character.ID);

            return sql;
        }
Esempio n. 10
0
 public void SendToClient(Connection client, bool clear = true)
 {
     for (int i = 0; i < _slots.Length; i++)
     {
         if( _slots[i] != 0 )
             client.SendPacket(new SetToolbarLink(_slots[i] & 0x7FFFFFFF, ((_slots[i] & 0x80000000) == 0) ? ToolbarItemSetRequest.TargetType.Item : ToolbarItemSetRequest.TargetType.Skill, i));
         else if (clear)
             client.SendPacket(new ClearToolbarLink((byte)i));
     }
 }