Exemple #1
0
        /// <summary>
        /// Occurs when the server has received a message from the client.
        /// </summary>
        protected void NetHooks_GetData(GetDataEventArgs args)
        {
            byte[]   bufferSegment = null;
            TSPlayer player        = null;

            if (args.Handled == true ||
                (player = TShock.Players.ElementAtOrDefault(args.Msg.whoAmI)) == null)
            {
                return;
            }

            bufferSegment = new byte[args.Length];
            System.Array.Copy(args.Msg.readBuffer, args.Index, bufferSegment, 0, args.Length);

            if (args.MsgID == PacketTypes.NpcStrike)
            {
                OTAPI.Terraria.NPC npc       = null;
                Packets.DamageNPC  dmgPacket = Packets.PacketMarshal.MarshalFromBuffer <Packets.DamageNPC>(bufferSegment);

                if (dmgPacket.NPCID < 0 || dmgPacket.NPCID > OTAPI.Terraria.Main.npc.Length ||
                    args.Msg.whoAmI < 0 || dmgPacket.NPCID > OTAPI.Terraria.Main.player.Length)
                {
                    return;
                }

                if ((npc = OTAPI.Terraria.Main.npc.ElementAtOrDefault(dmgPacket.NPCID)) == null)
                {
                    return;
                }

                if (DateTime.UtcNow.Subtract(player.LastThreat).TotalMilliseconds < 5000)
                {
                    return;
                }

                AddNPCDamage(npc, player.TPlayer, dmgPacket.Damage, Convert.ToBoolean(dmgPacket.CrititcalHit));
            }
        }
Exemple #2
0
        /// <summary>
        /// Should occur when an NPC dies; gives rewards out to all the players that hit it.
        /// </summary>
        protected void GiveRewardsForNPC(OTAPI.Terraria.NPC NPC)
        {
            List <PlayerDamage> playerDamageList = null;
            IBankAccount        account;
            TSPlayer            player;
            Money rewardMoney = 0L;

            lock (__dictionaryMutex)
            {
                if (DamageDictionary.ContainsKey(NPC))
                {
                    playerDamageList = DamageDictionary[NPC];

                    if (DamageDictionary.Remove(NPC) == false)
                    {
                        TShock.Log.ConsoleError("[SEconomy World] Removal of NPC after reward failed. This is an internal error.");
                    }
                }
            }

            if (playerDamageList == null)
            {
                return;
            }

            if (((NPC.boss && WorldConfiguration.MoneyFromBossEnabled) || (!NPC.boss && WorldConfiguration.MoneyFromNPCEnabled)) && !(NPC.SpawnedFromStatue && WorldConfiguration.IgnoreSpawnedFromStatue))
            {
                foreach (PlayerDamage damage in playerDamageList)
                {
                    if (damage.Player == null ||
                        (player = TShockAPI.TShock.Players.FirstOrDefault(i => i != null && i.Index == damage.Player.whoAmI)) == null ||
                        (account = Parent.GetBankAccount(player)) == null)
                    {
                        continue;
                    }

                    rewardMoney = CustomMultiplier * Convert.ToInt64(Math.Round(Convert.ToDouble(WorldConfiguration.MoneyPerDamagePoint) * damage.Damage));

                    //load override by NPC type, this allows you to put a modifier on the base for a specific mob type.
                    Configuration.WorldConfiguration.NPCRewardOverride overrideReward = WorldConfiguration.Overrides.FirstOrDefault(i => i.NPCID == NPC.type);
                    if (overrideReward != null)
                    {
                        rewardMoney = CustomMultiplier * Convert.ToInt64(Math.Round(Convert.ToDouble(overrideReward.OverridenMoneyPerDamagePoint) * damage.Damage));
                    }

                    if (rewardMoney <= 0 || player.Group.HasPermission("seconomy.world.mobgains") == false)
                    {
                        continue;
                    }

                    Journal.CachedTransaction fund = new Journal.CachedTransaction()
                    {
                        Aggregations            = 1,
                        Amount                  = rewardMoney,
                        DestinationBankAccountK = account.BankAccountK,
                        Message                 = NPC.FullName,
                        SourceBankAccountK      = Parent.WorldAccount.BankAccountK
                    };

                    if ((NPC.boss && WorldConfiguration.AnnounceBossKillGains) || (!NPC.boss && WorldConfiguration.AnnounceNPCKillGains))
                    {
                        fund.Options |= Journal.BankAccountTransferOptions.AnnounceToReceiver;
                    }

                    //commit it to the transaction cache
                    Parent.TransactionCache.AddCachedTransaction(fund);
                }
            }
        }