Ejemplo n.º 1
0
        //Stores newly created projectiles into a list along with its originated item
        public void OnNewProjectile(object sender, GetDataHandlers.NewProjectileEventArgs args)
        {
            if (!PvPController.config.enablePlugin)
            {
                return;
            }

            PvPPlayer player = new PvPPlayer(args.Owner);

            if (player == null || !player.TPlayer.hostile)
            {
                return;
            }

            PvPItem weapon;

            if (MiscData.accessoryOrArmorProjectiles.ContainsKey(args.Type))
            {
                weapon        = new PvPItem();
                weapon.damage = MiscData.accessoryOrArmorProjectiles[args.Type];
                weapon.name   = Lang.GetProjectileName(args.Type).ToString();
            }
            else if (MiscData.fromWhatWeapon.ContainsKey(args.Type))
            {
                weapon = new PvPItem(MiscData.fromWhatWeapon[args.Type]);
            }
            else
            {
                weapon = player.GetPlayerItem();
            }

            projectiles[args.Identity] = new PvPProjectile(args.Type);
            projectiles[args.Identity].SetOwner(args.Owner);
            projectiles[args.Identity].SetOriginatedItem(weapon);
        }
Ejemplo n.º 2
0
        private void GetData(GetDataEventArgs args)
        {
            MemoryStream data     = new MemoryStream(args.Msg.readBuffer, args.Index, args.Length);
            PvPPlayer    attacker = pvpers[args.Msg.whoAmI];

            if (attacker == null || !attacker.TPlayer.active || !attacker.ConnectionAlive)
            {
                return;
            }
            if (!attacker.TPlayer.hostile)
            {
                return;
            }

            switch (args.MsgID)
            {
            case PacketTypes.PlayerHurtV2:
                PvPPlayer         target          = pvpers[data.ReadByte()];
                PlayerDeathReason playerHitReason = PlayerDeathReason.FromReader(new BinaryReader(data));
                if (target == null || !target.ConnectionAlive || !target.Active)
                {
                    return;
                }
                if (playerHitReason.SourcePlayerIndex == -1)
                {
                    target.lastHitBy = null;
                    return;
                }

                PvPProjectile projectile = playerHitReason.SourceProjectileIndex == -1 ? null : projectiles[playerHitReason.SourceProjectileIndex];
                PvPItem       weapon     = projectile == null?attacker.GetPlayerItem() : projectile.itemOriginated;

                int inflictedDamage = PvPController.config.enableDamageChanges ? target.GetDamageDealt(attacker, weapon, projectile) : data.ReadByte();
                int damageReceived  = target.GetDamageReceived(inflictedDamage);
                data.ReadByte(); data.ReadByte();
                int knockback = data.ReadByte() - 1;

                target.lastHitBy         = attacker;
                target.lastHitWeapon     = weapon;
                target.lastHitProjectile = projectile;

                DataHandler.OnPlayerHurtted(args, attacker, target, weapon, projectile, playerHitReason,
                                            inflictedDamage, damageReceived, knockback);

                break;

            case PacketTypes.TogglePvp:
                DataHandler.OnPvPToggled(attacker);
                break;

            case PacketTypes.PlayerSlot:
                data.ReadByte();
                int slot = data.ReadByte();
                DataHandler.OnPlayerSlotUpdated(attacker, slot);
                break;

            case PacketTypes.PlayerDeathV2:
                DataHandler.OnPlayerDead(attacker);
                break;

            case PacketTypes.ProjectileDestroy:
                DataHandler.OnProjectileDestroyed(data);
                break;

            case PacketTypes.PlayerUpdate:
                DataHandler.OnPlayerUpdated(data, attacker);
                break;
            }
        }