/// <summary> /// Gets the weapon of a projectile. /// For certain projectiles, it will pull from a list of /// projectile-to-weapon-mapping Dictionaries and returns /// the weapon based off the dictionary mapping. /// </summary> /// <param Name="owner">Owner of projectile.</param> /// <param Name="type">Type of projectile.</param> /// <returns>Returns the item the projectile came from.</returns> public static PvPItem GetProjectileWeapon(PvPPlayer owner, int type) { PvPItem weapon; if (PresetData.PresetProjDamage.ContainsKey(type)) { weapon = new PvPItem { Damage = PresetData.PresetProjDamage[type], SpecialName = Lang.GetProjectileName(type).ToString() }; } else if (PresetData.ProjHooks.ContainsKey(type)) { weapon = new PvPItem(type); } else if (PresetData.FromWhatItem.ContainsKey(type)) { weapon = owner.FindPlayerItem(PresetData.FromWhatItem[type]); } else if (PresetData.MinionItem.ContainsKey(type)) { weapon = owner.FindPlayerItem(PresetData.MinionItem[type]); } else { weapon = owner.GetPlayerItem; } return(weapon); }
private void OnPlayerUpdated(object sender, PlayerUpdateArgs e) { e.player.TPlayer.vortexStealthActive = (e.pulley & 8) == 8; if (!PvPController.config.enablePlugin) { return; } if (e.player.previousSelectedItem != e.selectedSlot) { if (e.player.seeTooltip) { PvPItem item = PvPUtils.ConvertToPvPItem(e.player.TPlayer.inventory[e.selectedSlot]); int damage = TerrariaUtils.GetWeaponDamage(e.player, item); damage += PvPUtils.GetAmmoDamage(e.player, item); damage += PvPUtils.GetVortexDamage(e.player, item, damage); if (damage > 0) { string message = item.Name + ": " + damage + " damage"; PvPUtils.PlayerTextPopup(e.player, message, Color.Goldenrod); } } e.player.previousSelectedItem = e.selectedSlot; } }
public ProjectileNewArgs(GetDataEventArgs args, MemoryStream data, PvPPlayer attacker) { Args = args; Attacker = attacker; Identity = data.ReadInt16(); Position = new Vector2(data.ReadSingle(), data.ReadSingle()); Velocity = new Vector2(data.ReadSingle(), data.ReadSingle()); Knockback = data.ReadSingle(); Damage = data.ReadInt16(); Owner = data.ReadByte(); Type = data.ReadInt16(); AiFlags = (BitsByte)data.ReadByte(); Ai0 = 0; Ai1 = 0; if (AiFlags[0]) { Ai0 = data.ReadSingle(); } if (AiFlags[1]) { Ai1 = data.ReadSingle(); } Ai = new float[Projectile.maxAI]; Weapon = ProjectileUtils.GetProjectileWeapon(attacker, Type); }
//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); }
public static void ActivateSpectreBolt(PvPPlayer attacker, PvPPlayer target, PvPItem weapon, int dmg) { if (!weapon.magic) { return; } int Damage = dmg / 2; if (dmg / 2 <= 1) { return; } int?attackingIndex = null; if (Collision.CanHit(attacker.TPlayer.position, attacker.TPlayer.width, attacker.TPlayer.height, target.TPlayer.position, target.TPlayer.width, target.TPlayer.height)) { attackingIndex = target.Index; } if (attackingIndex == null) { return; } int num3 = (int)attackingIndex; double num4 = 4.0; float num5 = (float)Main.rand.Next(-100, 101); float num6 = (float)Main.rand.Next(-100, 101); double num7 = Math.Sqrt((double)num5 * (double)num5 + (double)num6 * (double)num6); float num8 = (float)(num4 / num7); float SpeedX = num5 * num8; float SpeedY = num6 * num8; ProjectileUtils.SpawnProjectile(attacker, attacker.X, attacker.Y, SpeedX, SpeedY, 356, Damage, 0.0f, attacker.Index, (float)num3, 0.0f); }
/// <summary> /// Gets the weapon of a projectile. /// For certain projectiles, it will pull from a list of /// projectile-to-weapon Dictionaries and returns /// the weapon based off the dictionary mapping. /// </summary> /// <param name="owner">Index of the owner of projectile.</param> /// <param name="type">Type of projectile.</param> /// <returns>Returns the item the projectile came from.</returns> public static PvPItem GetProjectileWeapon(PvPPlayer owner, int type) { PvPItem weapon; if (PresetData.PresetProjDamage.ContainsKey(type)) { weapon = new PvPItem(); } else if (PresetData.ProjHooks.ContainsKey(type)) { weapon = owner.FindPlayerItem(PresetData.ProjHooks[type]); } else if (PresetData.FromWhatItem.ContainsKey(type)) { weapon = owner.FindPlayerItem(PresetData.FromWhatItem[type]); } else if (PresetData.MinionItem.ContainsKey(type)) { weapon = owner.FindPlayerItem(PresetData.MinionItem[type]); } else { weapon = owner.HeldItem; } return(weapon); }
public static int GetVortexDamage(PvPPlayer attacker, PvPItem weapon, int damage) { double vanillaVortexMultiplier = 1.36; if (weapon.ranged && attacker.TPlayer.vortexStealthActive) { return((int)(((double)damage / vanillaVortexMultiplier * PvPController.config.vortexMultiplier) - damage)); } return(0); }
/// <summary> /// Generates a death message for a person based off the weapon and type of death. /// </summary> /// <param name="type">1 for normal hits, 2 for reflection hits such as thorns and turtle.</param> public static string GetPvPDeathMessage(string deathMessage, PvPItem weapon, PvPProjectile proj = null, int type = 1) { string tag = ""; if (type == 1) { tag = weapon?.netID != 0 || proj?.ItemOriginated?.netID != 0 ? "[i/p{0}:{1}] ".SFormat(proj?.ItemOriginated?.prefix ?? weapon?.prefix, proj?.ItemOriginated?.netID ?? weapon?.netID) : ""; } else if (type == 2) { tag = "[i:1150] "; } return(tag + deathMessage); }
/// <summary> /// Gets the damage of a weapon with all the player's buffs and stat boosts. /// </summary> public static int GetWeaponDamage(PvPPlayer attacker, PvPItem weapon) { int dmg = GetPrefixDamage(weapon); if (dmg > 0) { if (weapon.melee) { dmg = (int)(dmg * (double)attacker.TPlayer.meleeDamage); } else if (weapon.ranged) { dmg = (int)(dmg * (double)attacker.TPlayer.rangedDamage); if (weapon.useAmmo == AmmoID.Arrow || weapon.useAmmo == AmmoID.Stake) { dmg = (int)(dmg * (double)attacker.TPlayer.arrowDamage); } if (weapon.useAmmo == AmmoID.Bullet || weapon.useAmmo == AmmoID.CandyCorn) { dmg = (int)(dmg * (double)attacker.TPlayer.bulletDamage); } if (weapon.useAmmo == AmmoID.Rocket || weapon.useAmmo == AmmoID.StyngerBolt || (weapon.useAmmo == AmmoID.JackOLantern || weapon.useAmmo == AmmoID.NailFriendly)) { dmg = (int)(dmg * (double)attacker.TPlayer.rocketDamage); } } else if (weapon.thrown) { dmg = (int)(dmg * (double)attacker.TPlayer.thrownDamage); } else if (weapon.magic) { dmg = (int)(dmg * (double)attacker.TPlayer.magicDamage); } else if (weapon.summon) { dmg = (int)(dmg * (double)attacker.TPlayer.minionDamage); } } return(dmg); }
public static int GetAmmoDamage(PvPPlayer attacker, PvPItem weapon) { int ammoDamage = TerrariaUtils.GetWeaponDamage(attacker, attacker.GetFirstAvailableAmmo(weapon)); return(ammoDamage > 0 ? ammoDamage : 0); }
/// <summary> /// Displays the stats of a player and weapon on the right side of their screen. /// Stats include damage, projectile, debuffs and buffs, knockback, criticals, and defense. /// </summary> /// <param Name="player"></param> public static void DisplayInterface(PvPPlayer player) { StringBuilder sb = new StringBuilder(); PvPItem weapon = player.GetPlayerItem; PvPProjectile projectile = weapon.useAmmo == AmmoID.None ? player.GetPlayerItem.GetItemShoot : weapon.GetItemShoot.type > 0 ? weapon.GetItemShoot : player.GetFirstAvailableAmmo(weapon).GetItemShoot; sb.AppendLine(MiscUtils.LineBreaks(8)); sb.AppendLine("Weapon and Armor Stats (/toggletooltip or /tt)"); sb.AppendLine(new string('-', 40)); if (weapon.GetPvPDamage(player) > 0 && weapon.netID != 0) { sb.AppendLine(weapon.Name + ": " + weapon.GetPvPDamage(player) + " damage"); } if (PvPController.Config.EnableWeaponDebuffs) { if (weapon.GetDebuffInfo.BuffId != 0) { sb.AppendLine(" Inflicts {0} for {1}s." .SFormat(Lang.GetBuffName(weapon.GetDebuffInfo.BuffId), weapon.GetDebuffInfo.BuffDuration / 60.0)); } } if (PvPController.Config.EnableWeaponSelfBuffs) { if (weapon.GetSelfBuffInfo.BuffId != 0) { sb.AppendLine(" Inflicts {0} to self for {1}s." .SFormat(Lang.GetBuffName(weapon.GetSelfBuffInfo.BuffId), weapon.GetSelfBuffInfo.BuffDuration / 60.0)); } } if (projectile.type > 0) { int shoot = projectile.type; sb.AppendLine(" Shoots " + Lang.GetProjectileName(shoot)); if (PvPController.Config.EnableProjectileDebuffs) { if (projectile.GetDebuffInfo().BuffId != 0) { sb.AppendLine(" Inflicts {0} for {1}s." .SFormat(Lang.GetBuffName(projectile.GetDebuffInfo().BuffId), projectile.GetDebuffInfo().BuffDuration / 60.0)); } } if (PvPController.Config.EnableProjectileSelfBuffs) { if (projectile.GetSelfBuffInfo().BuffId != 0) { sb.AppendLine(" Inflicts {0} to self for {1}s." .SFormat(Lang.GetBuffName(projectile.GetSelfBuffInfo().BuffId), projectile.GetSelfBuffInfo().BuffDuration / 60.0)); } } } for (int x = 0; x < Player.maxBuffs; x++) { int buffType = player.TPlayer.buffType[x]; var debuffInfo = Database.GetBuffInfo(DbConsts.BuffTable, x, true); var selfBuffInfo = Database.GetBuffInfo(DbConsts.BuffTable, x, false); if (PvPController.Config.EnableBuffDebuff) { if (debuffInfo.BuffId != 0) { sb.AppendLine("Buff {0} applies {1} ({2}s) to weapons." .SFormat(Lang.GetBuffName(buffType), Lang.GetBuffName(debuffInfo.BuffId), debuffInfo.BuffDuration / 60.0).SeparateToLines()); } } if (PvPController.Config.EnableBuffSelfBuff) { if (selfBuffInfo.BuffId != 0) { sb.AppendLine("Buff {0} applies {1} to self for {2}s on attack." .SFormat(Lang.GetBuffName(buffType), Lang.GetBuffName(selfBuffInfo.BuffId), selfBuffInfo.BuffDuration / 60.0).SeparateToLines()); } } } if (PvPController.Config.EnableKnockback) { sb.AppendLine("Knockback: " + player.GetPlayerItem.GetKnockback(player)); } if (PvPController.Config.EnableCriticals) { if (player.GetCrit(weapon) > 0) { sb.AppendLine("Critical: " + player.GetCrit(weapon) + "%"); } } sb.AppendLine("Defense: " + player.GetPlayerDefense()); sb.AppendLine(MiscUtils.LineBreaks(50)); player.SendData(PacketTypes.Status, sb.ToString()); }
public PlayerHurtArgs(GetDataEventArgs args, PvPPlayer attacker, PvPPlayer target, PvPItem weapon, PvPProjectile projectile, PlayerDeathReason playerHitReason, int inflictedDamage, int damageReceived, int knockback) { this.args = args; this.attacker = attacker; this.target = target; this.weapon = weapon; this.projectile = projectile; this.playerHitReason = playerHitReason; this.inflictedDamage = inflictedDamage; this.damageReceived = damageReceived; this.knockback = knockback; }
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; } }
/// <summary> /// Gets the damage of a weapon based off its prefix. /// </summary> public static int GetPrefixDamage(PvPItem weapon) { int prefix = weapon.prefix; float damage = 1f; if (prefix == 3) { damage = 1.05f; } else if (prefix == 4) { damage = 1.1f; } else if (prefix == 5) { damage = 1.15f; } else if (prefix == 6) { damage = 1.1f; } else if (prefix == 81) { damage = 1.15f; } else if (prefix == 8) { damage = 0.85f; } else if (prefix == 10) { damage = 0.85f; } else if (prefix == 12) { damage = 1.05f; } else if (prefix == 13) { damage = 0.9f; } else if (prefix == 16) { damage = 1.1f; } else if (prefix == 20) { damage = 1.1f; } else if (prefix == 21) { damage = 1.1f; } else if (prefix == 82) { damage = 1.15f; } else if (prefix == 22) { damage = 0.85f; } else if (prefix == 25) { damage = 1.15f; } else if (prefix == 58) { damage = 0.85f; } else if (prefix == 26) { damage = 1.1f; } else if (prefix == 28) { damage = 1.15f; } else if (prefix == 83) { damage = 1.15f; } else if (prefix == 30) { damage = 0.9f; } else if (prefix == 31) { damage = 0.9f; } else if (prefix == 32) { damage = 1.1f; } else if (prefix == 34) { damage = 1.1f; } else if (prefix == 35) { damage = 1.15f; } else if (prefix == 52) { damage = 0.9f; } else if (prefix == 37) { damage = 1.1f; } else if (prefix == 53) { damage = 1.1f; } else if (prefix == 55) { damage = 1.05f; } else if (prefix == 59) { damage = 1.15f; } else if (prefix == 60) { damage = 1.15f; } else if (prefix == 39) { damage = 0.7f; } else if (prefix == 40) { damage = 0.85f; } else if (prefix == 41) { damage = 0.9f; } else if (prefix == 57) { damage = 1.18f; } else if (prefix == 43) { damage = 1.1f; } else if (prefix == 46) { damage = 1.07f; } else if (prefix == 50) { damage = 0.8f; } else if (prefix == 51) { damage = 1.05f; } return((int)Math.Round(Database.GetData <int>(DbConsts.ItemTable, weapon.netID, DbConsts.Damage) * (double)damage)); }
public static int GetPrefixDamage(PvPItem weapon) { int prefix = weapon.prefix; float damage = 1f; if (prefix == 3) { damage = 1.05f; } else if (prefix == 4) { damage = 1.1f; } else if (prefix == 5) { damage = 1.15f; } else if (prefix == 6) { damage = 1.1f; } else if (prefix == 81) { damage = 1.15f; } else if (prefix == 8) { damage = 0.85f; } else if (prefix == 10) { damage = 0.85f; } else if (prefix == 12) { damage = 1.05f; } else if (prefix == 13) { damage = 0.9f; } else if (prefix == 16) { damage = 1.1f; } else if (prefix == 20) { damage = 1.1f; } else if (prefix == 21) { damage = 1.1f; } else if (prefix == 82) { damage = 1.15f; } else if (prefix == 22) { damage = 0.85f; } else if (prefix == 25) { damage = 1.15f; } else if (prefix == 58) { damage = 0.85f; } else if (prefix == 26) { damage = 1.1f; } else if (prefix == 28) { damage = 1.15f; } else if (prefix == 83) { damage = 1.15f; } else if (prefix == 30) { damage = 0.9f; } else if (prefix == 31) { damage = 0.9f; } else if (prefix == 32) { damage = 1.1f; } else if (prefix == 34) { damage = 1.1f; } else if (prefix == 35) { damage = 1.15f; } else if (prefix == 52) { damage = 0.9f; } else if (prefix == 37) { damage = 1.1f; } else if (prefix == 53) { damage = 1.1f; } else if (prefix == 55) { damage = 1.05f; } else if (prefix == 59) { damage = 1.15f; } else if (prefix == 60) { damage = 1.15f; } else if (prefix == 39) { damage = 0.7f; } else if (prefix == 40) { damage = 0.85f; } else if (prefix == 41) { damage = 0.9f; } else if (prefix == 57) { damage = 1.18f; } else if (prefix == 43) { damage = 1.1f; } else if (prefix == 46) { damage = 1.07f; } else if (prefix == 50) { damage = 0.8f; } else if (prefix == 51) { damage = 1.05f; } return((int)Math.Round(PvPController.config.itemInfo[weapon.netID].damage * (double)damage)); }
/// <summary> /// Generates a death message for a person based off the weapon and type of death. /// </summary> /// <param Name="attacker">The person inflicting the hit.</param> /// <param Name="deadplayer">The target receiving the death message.</param> /// <param Name="weapon">The weapon used to hit the target.</param> /// <param Name="type">1 for normal hits, 2 for reflection hits such as thorns and turtle.</param> /// <returns>A string of the death message.</returns> public static string GetPvPDeathMessage(PvPPlayer attacker, PvPPlayer deadplayer, PvPItem weapon, int type = 1) { Random random = new Random(); string deathmessage = ""; if (type == 1) { deathmessage = PvPController.Config.NormalDeathMessages[random.Next(PvPController.Config.NormalDeathMessages.Count)]; } else if (type == 2) { deathmessage = PvPController.Config.ReflectedDeathMessages[random.Next(PvPController.Config.ReflectedDeathMessages.Count)]; } string tag = PvPController.Config.DeathItemTag; if (PvPController.Config.DeathItemTag == "weapon" && type == 1) { tag = weapon.netID != 0 ? "[i/p{0}:{1}] ".SFormat(weapon.prefix, weapon.netID) : ""; } else if (PvPController.Config.DeathItemTag == "weapon" && type == 2) { tag = "[i:1150] "; } return(tag + deadplayer.Name + deathmessage + attacker.Name + "'s " + weapon.Name + "."); }
public static void OnPlayerHurtted(GetDataEventArgs args, PvPPlayer attacker, PvPPlayer target, PvPItem weapon, PvPProjectile projectile, PlayerDeathReason playerHitReason, int inflictedDamage, int damageReceived, int knockback) { if (PlayerHurtted != null) { PlayerHurtted(typeof(DataHandler), new PlayerHurtArgs(args, attacker, target, weapon, projectile, playerHitReason, inflictedDamage, damageReceived, knockback)); } }