Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Commit

Permalink
Motherboard improvements, still MP bugged
Browse files Browse the repository at this point in the history
  • Loading branch information
Jofairden committed Jul 13, 2017
1 parent 515f940 commit b112ce4
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 19 deletions.
12 changes: 8 additions & 4 deletions Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
95 changes: 80 additions & 15 deletions NPCs/Motherboard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
Expand All @@ -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
Expand Down Expand Up @@ -43,6 +45,7 @@ public class Motherboard : ModNPC

#region "Переменные"

private int _appearTime;
private bool _firstAi = true; // Первый ли раз вызван метод AI
private bool _firstState = true; // Первая ли стадия
private List<int> _signalDrones = new List<int>(); // ID сигнальных дронов
Expand Down Expand Up @@ -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<MotherboardBag>();
}

Expand All @@ -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<int>();
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;
Expand Down Expand Up @@ -283,8 +350,6 @@ private void ChangeStady() // Попытка смены стадии
}
}

private int _appearTime;

private void ChangeAi() // Сменяет состояние (преследование/исчезновение/появление)
{
if (_firstState)
Expand Down Expand Up @@ -420,38 +485,38 @@ public override void NPCLoot()
{
if (Main.rand.NextBool())
{
Helper.NewItemFast(npc.position, npc.Size, mod.ItemType<SoulofMind>(), Main.rand.Next(20, 40));
this.SpawnItem((short) mod.ItemType<SoulofMind>(), 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<MotherboardMask>());
this.SpawnItem((short) mod.ItemType<MotherboardMask>());
}
}

if (Main.rand.Next(10) == 0)
{
Helper.NewItemFast(npc.position, npc.Size, mod.ItemType<MotherboardTrophy>());
this.SpawnItem((short) mod.ItemType<MotherboardTrophy>());
}
if (Main.rand.Next(3) == 0)
{
Helper.NewItemFast(npc.position, npc.Size, mod.ItemType<BenderLegs>());
this.SpawnItem((short) mod.ItemType<BenderLegs>());
}
if (Main.rand.Next(10) == 0)
{
Helper.NewItemFast(npc.position, npc.Size, mod.ItemType<FlaskCore>());
this.SpawnItem((short) mod.ItemType<FlaskCore>());
}

if (NPC.downedMoonlord && Main.rand.NextBool())
{
Helper.NewItemFast(npc.position, npc.Size, mod.ItemType<CarbonSteel>(), Main.rand.Next(6, 12));
this.SpawnItem((short) mod.ItemType<CarbonSteel>(), Main.rand.Next(6, 12));
}
}
}
Expand Down

0 comments on commit b112ce4

Please sign in to comment.