Example #1
0
        public static bool HandleModifyMoneyCommand(string[] args, CommandGroup handler)
        {
            if (args.Count() < 1)
                return false;

            Player target = handler.getSelectedPlayer();
            if (target == null)
                return handler.SendErrorMessage(CypherStrings.NoCharSelected);

            // check online security
            if (handler.HasLowerSecurity(target, 0))
                return false;

            long addmoney;
            long.TryParse(args[0], out addmoney);

            long moneyuser = (long)target.GetMoney();

            if (addmoney < 0)
            {
                ulong newmoney = (ulong)(moneyuser + addmoney);

                Log.outDebug(ObjMgr.GetCypherString(CypherStrings.CurrentMoney), moneyuser, addmoney, newmoney);
                if (newmoney <= 0)
                {
                    handler.SendSysMessage(CypherStrings.YouTakeAllMoney, handler.GetNameLink(target));
                    if (handler.needReportToTarget(target))
                       ChatHandler.SendSysMessage(target, CypherStrings.YoursAllMoneyGone, handler.GetNameLink());

                    target.SetMoney(0);
                }
                else
                {
                    if (newmoney > PlayerConst.MaxMoneyAmount)
                        newmoney = PlayerConst.MaxMoneyAmount;

                    handler.SendSysMessage(CypherStrings.YouTakeMoney, Math.Abs(addmoney), handler.GetNameLink(target));
                    if (handler.needReportToTarget(target))
                        ChatHandler.SendSysMessage(target, CypherStrings.YoursMoneyTaken, handler.GetNameLink(), Math.Abs(addmoney));
                    target.SetMoney(newmoney);
                }
            }
            else
            {
                handler.SendSysMessage( CypherStrings.YouGiveMoney, addmoney, handler.GetNameLink(target));
                if (handler.needReportToTarget(target))
                    ChatHandler.SendSysMessage(target, CypherStrings.YoursMoneyGiven, handler.GetNameLink(), addmoney);

                if (addmoney >= PlayerConst.MaxMoneyAmount)
                    target.SetMoney(PlayerConst.MaxMoneyAmount);
                else
                    target.ModifyMoney(addmoney);
            }

            Log.outDebug(ObjMgr.GetCypherString(CypherStrings.NewMoney), moneyuser, addmoney, target.GetMoney());
            return true;
        }
Example #2
0
        public bool SendSysMessage(CypherStrings str, params object[] args)
        {
            string input   = ObjMgr.GetCypherString(str);
            string pattern = @"%(\d+(\.\d+)?)?(d|f|s|u)";

            int    count  = 0;
            string result = Regex.Replace(input, pattern, m =>
            {
                return(String.Concat("{", count++, "}"));
            });

            return(SendSysMessage(result, args));
        }
Example #3
0
        public static void SendSysMessage(WorldSession session, CypherStrings message, params object[] args)
        {
            string msg = string.Format(ObjMgr.GetCypherString(message), args);

            SendChatMessage(session, ChatMsg.System, Language.Universal, msg);
        }
Example #4
0
 public static void SendSysMessage(WorldObject obj, CypherStrings message, params object[] args)
 {
     SendSysMessage(obj.GetSession(), ObjMgr.GetCypherString(message), args);
 }
Example #5
0
        public static void HandleTrainerList(ref PacketReader packet, ref WorldSession session)
        {
            ulong  guid = packet.ReadUInt64();
            string str  = ObjMgr.GetCypherString(CypherStrings.NpcTrainerHello);

            Creature unit = session.GetPlayer().GetNPCIfCanInteractWith(guid, NPCFlags.Trainer);

            if (unit == null)
            {
                Log.outDebug("WORLD: SendTrainerList - Unit (GUID: {0}) not found or you can not interact with him.", ObjectGuid.GuidLowPart(guid));
                return;
            }

            // remove fake death
            //if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
            //GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);

            // trainer list loaded at check;
            if (!unit.isTrainerOf(session.GetPlayer(), true))
            {
                return;
            }

            CreatureTemplate ci = unit.GetCreatureTemplate();

            if (ci == null)
            {
                Log.outDebug("WORLD: SendTrainerList - (GUID: {0}) NO CREATUREINFO!", ObjectGuid.GuidLowPart(guid));
                return;
            }
            TrainerSpellData trainer_spells = unit.GetTrainerSpells();

            if (trainer_spells == null)
            {
                Log.outDebug("WORLD: SendTrainerList - Training spells not found for creature (GUID: {0} Entry: {1})", ObjectGuid.GuidLowPart(guid), unit.GetEntry());
                return;
            }
            PacketWriter data = new PacketWriter(Opcodes.SMSG_TrainerList);

            data.WriteUInt64(guid);
            data.WriteUInt32(trainer_spells.trainerType);
            data.WriteUInt32(133);

            int count_pos = data.wpos();

            data.WriteUInt32(trainer_spells.spellList.Count);

            // reputation discount
            float fDiscountMod           = session.GetPlayer().GetReputationPriceDiscount(unit);
            bool  can_learn_primary_prof = session.GetPlayer().GetFreePrimaryProfessionPoints() > 0;

            uint count = 0;

            foreach (var spell in trainer_spells.spellList.Values)
            {
                bool valid = true;
                bool primary_prof_first_rank = false;
                for (var i = 0; i < 3; ++i)
                {
                    if (spell.learnedSpell[i] == 0)
                    {
                        continue;
                    }
                    if (!session.GetPlayer().IsSpellFitByClassAndRace(spell.learnedSpell[i]))
                    {
                        valid = false;
                        break;
                    }
                    SpellInfo spellentry = SpellMgr.GetSpellInfo(spell.learnedSpell[i]);
                    if (spellentry.IsPrimaryProfessionFirstRank())
                    {
                        primary_prof_first_rank = true;
                    }
                }
                if (!valid)
                {
                    continue;
                }

                TrainerSpellState state = session.GetPlayer().GetTrainerSpellState(spell);
                data.WriteUInt32(spell.spellId);                      // learned spell (or cast-spell in profession case)
                data.WriteUInt8((byte)(state == TrainerSpellState.GreenDisabled ? TrainerSpellState.Green : state));
                data.WriteUInt32((uint)Math.Floor(spell.spellCost * fDiscountMod));

                data.WriteUInt8((byte)spell.reqLevel);
                data.WriteUInt32(spell.reqSkill);
                data.WriteUInt32(spell.reqSkillValue);
                //prev + req or req + 0
                var maxReq = 0;
                for (var i = 0; i < 3; ++i)
                {
                    if (spell.learnedSpell[i] == 0)
                    {
                        continue;
                    }
                    uint prevSpellId = SpellMgr.GetPrevSpellInChain(spell.learnedSpell[i]);
                    if (prevSpellId != 0)
                    {
                        data.WriteUInt32(prevSpellId);
                        maxReq++;
                    }
                    if (maxReq == 2)
                    {
                        break;
                    }

                    //SpellsRequiringSpellMapBounds spellsRequired = sSpellMgr->GetSpellsRequiredForSpellBounds(tSpell->learnedSpell[i]);
                    //for (SpellsRequiringSpellMap::const_iterator itr2 = spellsRequired.first; itr2 != spellsRequired.second && maxReq < 3; ++itr2)
                    {
                        //data.WriteUInt32(itr2->second);
                        //++maxReq;
                    }
                    //if (maxReq == 2)
                    //break;
                }
                while (maxReq < 2)
                {
                    data.WriteUInt32(0);
                    maxReq++;
                }

                data.WriteInt32(primary_prof_first_rank && can_learn_primary_prof ? 1 : 0);
                count++;
            }
            data.WriteCString(str);
            data.Replace <uint>(count_pos, count);
            session.Send(data);
        }