Example #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;
        }
Example #2
0
 public Task(TaskType type, Connection client = null, object args = null)
 {
     Type = type;
     _client = client;
     _args = args;
     Query = null;
 }
Example #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));
        }
Example #4
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));
     }
 }
Example #5
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;
        }
Example #6
0
 public void NextStep(Connection client, QuestStep step)
 {
     byte stepIndex = step.StepNumber;
     stepIndex++;
     if (stepIndex < _steps.Length)
     {
         // Valid next step, activate it
         client.Character.SetActiveQuestStep(_questID, stepIndex);
         _steps[stepIndex].Activate(client);
     }
     else
     {
         // Done with this quest!
         client.Character.CompleteQuest(_questID);
     }
 }
Example #7
0
 public void Award(Connection client, uint questID)
 {
     switch (_type)
     {
         case RewardType.Gold:
             Program.Server.TaskProcessor.AddTask(new Task(Task.TaskType.GiveGoldExpFame, client, new GiveGoldExpFameArgs(_context, 0, 0, GiveGoldExpFameArgs.TheReason.Quest, questID)));
             break;
         case RewardType.Exp:
             Program.Server.TaskProcessor.AddTask(new Task(Task.TaskType.GiveGoldExpFame, client, new GiveGoldExpFameArgs(0, _context, 0, GiveGoldExpFameArgs.TheReason.Quest, questID)));
             break;
         case RewardType.Fame:
             Program.Server.TaskProcessor.AddTask(new Task(Task.TaskType.GiveGoldExpFame, client, new GiveGoldExpFameArgs(0, 0, _context, GiveGoldExpFameArgs.TheReason.Quest, questID)));
             break;
         case RewardType.Item:
             Program.Server.TaskProcessor.AddTask(new Task(Task.TaskType.GiveItem, client, new GiveItemArgs(_context, GiveItemArgs.TheReason.Quest, questID)));
             break;
         case RewardType.Teleport:
             Program.Server.TaskProcessor.AddTask(new Task(Task.TaskType.Teleport, client, Program.Server.GetLocation(_context)));
             break;
         case RewardType.Skill:
             throw new NotImplementedException();
     }
 }
Example #8
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;
        }
Example #9
0
 public void Activate(Connection client)
 {
     switch (_completionType)
     {
         default:
         case CompletionType.KillMonster:
         case CompletionType.CollectItem:
         case CompletionType.GoToLocation:
         case CompletionType.ReachLevel:
             throw new NotImplementedException();
         case CompletionType.WearItem:
             if( !CheckItemEquipCompletion(client) )
                 client.OnItemEquipped += Client_OnItemEquipped;
             break;
         case CompletionType.TalkToNPC:
             client.OnQuestDialogFinished += Client_OnQuestDialogFinished;
             break;
     }
 }
Example #10
0
        void FinishStep(Connection client)
        {
            // Award rewards
            foreach (QuestReward qr in _rewards)
            {
                qr.Award(client, _quest);
            }

            // Is the whole quest done?
            Quest q = Program.Server.GetQuest(_quest);
            q.NextStep(client, this);
        }
Example #11
0
 bool CheckItemEquipCompletion(Connection client)
 {
     if (client.Character.HasItemEquipped(_completionID))
     {
         FinishStep(client);
         return true;
     }
     return false;
 }
Example #12
0
        public void PlayerEnterMap(Connection client)
        {
            CharacterInfo ci = client.Character;

            _maps[ci.MapID].AddPlayer(client, ci);
        }
Example #13
0
 public void UpdatePlayerPosition(Connection client, CharacterPositionClass cpc)
 {
     _maps[client.Character.MapID].UpdatePlayerPosition(client, cpc);
 }
Example #14
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);
        }
Example #15
0
 private void Client_OnToolbarItemClear(Connection arg1, byte arg2)
 {
     TaskProcessor.AddTask(new Task(Task.TaskType.ToolbarItemClear, arg1, arg2));
 }
Example #16
0
 public void ProcessMoveRequest(Connection client, CharacterPositionClass mtp)
 {
     _maps[client.Character.MapID].ProcessMoveRequest(client, mtp);
 }
Example #17
0
        public void NextDialog(Connection client)
        {
            Quest q = Program.Server.GetQuest(client.CurrentQuestID);
            byte step = client.Character.GetQuestStep(client.CurrentQuestID);
            byte line = client.CurrentQuestLine;

            // Next line
            line++;

            QuestStep qs = q.GetStep(step);
            if (line < qs.LineCount)
            {
                QuestLine ql = qs.GetLine(line);
                client.SetCurrentQuest(_id, q.QuestID, line);
                bool lastLine = (line >= (qs.LineCount - 1));
                ql.SendToClient(client, !lastLine);

                if( lastLine )
                    client.QuestDialogFinished(_id);
            }
            else
                client.SetCurrentQuest(_id, q.QuestID, 0);
        }
Example #18
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));
            }
            */
        }
Example #19
0
 public void AddConnection(Connection c)
 {
     _connectionsLock.WaitOne();
     _connections.Add(c);
     _connectionsLock.ReleaseMutex();
 }
Example #20
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;
        }
Example #21
0
        void DoAttack(Connection enemy)
        {
            Vector myPos = Utils.DecodeCellIndex(_loc.Map, _cellIndex);
            Vector ePos = Utils.DecodeCellIndex(enemy.Character.MapID, enemy.Character.CellIndex);

            Vector fromEnemy = myPos - ePos;
            double dist = fromEnemy.Length;
            if (dist > _template.IdleMoveSpeed)
            {
                fromEnemy.Normalize();
                fromEnemy *= 2;
                _moveTarget = ePos + fromEnemy;
                _moveTargetCell = Utils.EncodeCellIndex(_mapID, _moveTarget);
                _moveSpeed = _template.IdleMoveSpeed;
                _aiTimer = 1;
                UpdateMove(0);
            }

            if (_aiTimer <= 0 && dist < _template.IdleMoveSpeed)
            {
                // Attack the player
                bool critical = ( Program.Server.Rand.NextDouble() < _template.CriticalChance );
                int damage = Program.Server.Rand.Next(_template.AttackMin, _template.AttackMax);
                if( critical )
                    damage *= 2;

                ushort attackType = (ushort)(critical ? 3 : 1);
                Program.Server.TaskProcessor.AddTask(new Task(Task.TaskType.MonsterAttackPlayer, enemy, new object[] { this, damage, attackType }));

                _aiTimer = _template.AttackDelay;
            }
        }
Example #22
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));
        }
Example #23
0
 void UpdateAI(double deltaSeconds, Connection enemy)
 {
     switch (_aiState)
     {
         case AIState.Idle:
             if (_aiTimer <= 0)
             {
                 if (Program.Server.Rand.NextDouble() < _template.IdleMoveChance)
                 {
                     // Wander to a new spot
                     _moveTargetCell = _loc.RandomCell;
                     _moveTarget = Utils.DecodeCellIndex(_loc.Map, _moveTargetCell);
                     _moveSpeed = _template.IdleMoveSpeed;
                 }
                 else
                     _aiTimer = 1;
             }
             break;
         case AIState.Attack:
             DoAttack(enemy);
             break;
         case AIState.Dead:
             break;
     }
 }
Example #24
0
        public void UpdatePlayerPosition(Connection client, CharacterPositionClass cpc)
        {
            client.Character.CellIndex = cpc.CellIndex;

            // Inform other clients
            ObserveMovementPacket omp = new ObserveMovementPacket(client.Character.WorldID, cpc.CellIndex, client.Character.MoveSpeed);
            foreach (Connection c in _players.Values)
            {
                if (c.AccountID != client.AccountID)
                {
                    // Send move update
                    c.SendPacket(omp);
                }
            }
        }
Example #25
0
 public void NextDialog(Connection client)
 {
     _npcs[client.CurrentQuestNPC].NextDialog(client);
 }
Example #26
0
 public void NextDialog(Connection client)
 {
     _maps[client.Character.MapID].NextDialog(client);
 }
Example #27
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);
                }
            }
        }
Example #28
0
 private void Client_OnUseItem(Connection arg1, uint arg2)
 {
     TaskProcessor.AddTask(new Task(Task.TaskType.UseItem, arg1, arg2));
 }