From b112ce4faa558ad30c3fb894b3ee37e9afdcda9e Mon Sep 17 00:00:00 2001 From: Jofairden Date: Thu, 13 Jul 2017 16:50:57 +0200 Subject: [PATCH] Motherboard improvements, still MP bugged --- Helper.cs | 12 ++++-- NPCs/Motherboard.cs | 95 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 88 insertions(+), 19 deletions(-) diff --git a/Helper.cs b/Helper.cs index f64b296c..7a383893 100644 --- a/Helper.cs +++ b/Helper.cs @@ -55,10 +55,14 @@ public static bool NoBiomeNormalSpawn(NPCSpawnInfo spawnInfo) } #endregion - public static Item NewItemFast(Vector2 position, Vector2 size, int type, int stack = 1) - { - return Main.item[Item.NewItem((int) position.X, (int) position.Y, (int) size.X, (int) size.Y, type, stack)]; - } + public static Item SpawnItem(this ModNPC npc, short type, int stack = 1) + => SpawnItem(npc.npc, type, stack); + + public static Item SpawnItem(this NPC npc, short type, int stack = 1) + => Main.item[Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, type, stack)]; + + public static Item SpawnItem(Vector2 position, Vector2 size, short type, int stack = 1) + => Main.item[Item.NewItem((int)position.X, (int)position.Y, (int)size.X, (int)size.Y, type, stack)]; public static Vector2 RandomPosition(Vector2 pos1, Vector2 pos2) { diff --git a/NPCs/Motherboard.cs b/NPCs/Motherboard.cs index 89e6da7e..267caa5d 100644 --- a/NPCs/Motherboard.cs +++ b/NPCs/Motherboard.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -9,6 +10,7 @@ namespace Tremor.NPCs { // TODO: fix Motherboard despawn on first hit + // TODO: motherboard does not spawn in MP // TODO: rewrite this thing, lol [AutoloadBossHead] public class Motherboard : ModNPC @@ -43,6 +45,7 @@ public class Motherboard : ModNPC #region "Переменные" + private int _appearTime; private bool _firstAi = true; // Первый ли раз вызван метод AI private bool _firstState = true; // Первая ли стадия private List _signalDrones = new List(); // ID сигнальных дронов @@ -75,24 +78,32 @@ public override void SetStaticDefaults() { DisplayName.SetDefault("Motherboard"); Main.npcFrameCount[npc.type] = 6; + + NPCID.Sets.MustAlwaysDraw[npc.type] = true; + NPCID.Sets.NeedsExpertScaling[npc.type] = true; } public override void SetDefaults() { - npc.dontTakeDamage = true; - npc.noTileCollide = true; - npc.noGravity = true; npc.lifeMax = 45000; npc.damage = 30; npc.knockBackResist = 0f; npc.defense = 70; npc.width = 170; npc.height = 160; - npc.aiStyle = 2; + npc.aiStyle = 2; // -1 + npc.npcSlots = 50f; + music = MusicID.Boss3; + + npc.dontTakeDamage = true; + npc.noTileCollide = true; + npc.noGravity = true; npc.boss = true; + npc.lavaImmune = true; + npc.HitSound = SoundID.NPCHit4; npc.DeathSound = SoundID.NPCDeath10; - music = 13; + bossBag = mod.ItemType(); } @@ -102,6 +113,62 @@ public override void ScaleExpertStats(int numPlayers, float bossLifeScale) npc.damage = (int)(npc.damage * 0.6f); } + public override bool UsesPartyHat() => false; + + // ?? Doesn't seem to fix much + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(_appearTime); + writer.Write(_firstAi); + writer.Write(_firstState); + writer.Write(_signalDrones.Count); + foreach (int drone in _signalDrones) + { + writer.Write(drone); + } + writer.Write(_lastSignalDron); + writer.Write(_shootNow); + writer.Write(_timeToNextDrone); + writer.Write(_timeToShoot); + writer.Write(_timeToLaser); + writer.Write(_currentFrame); + writer.Write(_timeToAnimation); + writer.Write(_clampers.Count); + foreach (int clamper in _clampers) + { + writer.Write(clamper); + } + writer.Write(_secondShootTime); + writer.Write(_ai); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + _appearTime = reader.ReadInt32(); + _firstAi = reader.ReadBoolean(); + _firstState = reader.ReadBoolean(); + int c = reader.ReadInt32(); + _signalDrones = new List(); + for (int i = 0; i < c; i++) + { + _signalDrones[i] = reader.ReadInt32(); + } + _lastSignalDron = reader.ReadInt32(); + _shootNow = reader.ReadBoolean(); + _timeToNextDrone = reader.ReadInt32(); + _timeToShoot = reader.ReadInt32(); + _timeToLaser = reader.ReadInt32(); + _currentFrame = reader.ReadInt32(); + _timeToAnimation = reader.ReadInt32(); + c = reader.ReadInt32(); + for (int i = 0; i < c; i++) + { + _clampers[i] = reader.ReadInt32(); + } + _secondShootTime = reader.ReadInt32(); + _ai = reader.ReadInt32(); + } + private void Teleport() { npc.aiStyle = 2; @@ -283,8 +350,6 @@ private void ChangeStady() // Попытка смены стадии } } - private int _appearTime; - private void ChangeAi() // Сменяет состояние (преследование/исчезновение/появление) { if (_firstState) @@ -420,38 +485,38 @@ public override void NPCLoot() { if (Main.rand.NextBool()) { - Helper.NewItemFast(npc.position, npc.Size, mod.ItemType(), Main.rand.Next(20, 40)); + this.SpawnItem((short) mod.ItemType(), Main.rand.Next(20, 40)); } if (Main.rand.NextBool()) { - Helper.NewItemFast(npc.position, npc.Size, ItemID.GreaterHealingPotion, Main.rand.Next(5, 15)); + this.SpawnItem(ItemID.GreaterHealingPotion, Main.rand.Next(5, 15)); } if (Main.rand.NextBool()) { - Helper.NewItemFast(npc.position, npc.Size, ItemID.HallowedBar, Main.rand.Next(15, 35)); + this.SpawnItem(ItemID.HallowedBar, Main.rand.Next(15, 35)); } if (Main.rand.Next(7) == 0) { - Helper.NewItemFast(npc.position, npc.Size, mod.ItemType()); + this.SpawnItem((short) mod.ItemType()); } } if (Main.rand.Next(10) == 0) { - Helper.NewItemFast(npc.position, npc.Size, mod.ItemType()); + this.SpawnItem((short) mod.ItemType()); } if (Main.rand.Next(3) == 0) { - Helper.NewItemFast(npc.position, npc.Size, mod.ItemType()); + this.SpawnItem((short) mod.ItemType()); } if (Main.rand.Next(10) == 0) { - Helper.NewItemFast(npc.position, npc.Size, mod.ItemType()); + this.SpawnItem((short) mod.ItemType()); } if (NPC.downedMoonlord && Main.rand.NextBool()) { - Helper.NewItemFast(npc.position, npc.Size, mod.ItemType(), Main.rand.Next(6, 12)); + this.SpawnItem((short) mod.ItemType(), Main.rand.Next(6, 12)); } } }