// for the most part vanilla private void ForceColliding(On.Terraria.Player.orig_Update_NPCCollision orig, Player self) { Rectangle rectangle = new Rectangle((int)self.position.X, (int)self.position.Y, self.width, self.height); for (int i = 0; i < 200; i++) { if (!Main.npc[i].active || Main.npc[i].friendly || Main.npc[i].damage <= 0) { continue; } var npc = Main.npc[i]; int type = npc.type; Rectangle npcRect = new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height); int specialHit = -1; float damageMultipler = 1; NPC.GetMeleeCollisionData(rectangle, i, ref specialHit, ref damageMultipler, ref npcRect); if (rectangle.Intersects(npcRect) && type == NPCType <ArenaBlocker>() && NPCLoader.CanHitPlayer(npc, self, ref specialHit)) { NPCLoader.OnHitPlayer(npc, self, npc.damage, false); var dam = npc.damage; var crit = false; NPCLoader.ModifyHitPlayer(npc, self, ref dam, ref crit); return; } } orig(self); }
private void PlatformCollision(On.Terraria.Player.orig_Update_NPCCollision orig, Player self) { if (self.controlDown) { self.GetModPlayer <IcePlayer>().PlatformTimer = 5; } if (self.controlDown || self.GetModPlayer <IcePlayer>().PlatformTimer > 0 || self.GoingDownWithGrapple) { orig(self); return; } foreach (NPC npc in Main.npc.Where(n => n.active && n.modNPC != null && n.modNPC is MovingPlatform)) { if (new Rectangle((int)self.position.X, (int)self.position.Y + (self.height), self.width, 1).Intersects (new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, 8 + (self.velocity.Y > 0 ? (int)self.velocity.Y : 0))) && self.position.Y <= npc.position.Y) { if (!self.justJumped && self.velocity.Y >= 0) { self.gfxOffY = npc.gfxOffY; self.velocity.Y = 0; self.fallStart = (int)(self.position.Y / 16f); self.position.Y = npc.position.Y - self.height + 4; orig(self); } } } orig(self); }
public void CollisionDetour(On.Terraria.Player.orig_Update_NPCCollision orig, Player self) { SoraPlayer sp = self.GetModPlayer <SoraPlayer>(); if (sp.collisionDown) { if (!self.justJumped && self.velocity.Y >= 0) { self.velocity.Y = 0; self.fallStart = (int)(self.position.Y / 16f); self.position.Y = sp.collisionPoints.Y; //self.position.Y = npc.position.Y - self.height + 4; // orig(self); } } if (sp.collisionUp) { if (self.velocity.Y <= 0) { //self.gfxOffY = npc.gfxOffY; self.velocity.Y = 0; self.fallStart = (int)(self.position.Y / 16f); self.position.Y = sp.collisionPoints.Y - self.height / 2; //self.position.Y = npc.position.Y - self.height + 4; // orig(self); } } if (sp.collisionLeft) { if (self.velocity.X <= 0) { //self.gfxOffY = npc.gfxOffY; self.velocity.X = 0; //self.fallStart = (int)(self.position.Y / 16f); self.position.X = sp.collisionPoints.X - self.width / 2; //self.position.Y = npc.position.Y - self.height + 4; - self.width - // orig(self); } } if (sp.collisionRight) { if (self.velocity.X >= 0) { //self.gfxOffY = npc.gfxOffY; self.velocity.X = 0; //self.fallStart = (int)(self.position.Y / 16f); self.position.X = sp.collisionPoints.X; //self.position.Y = npc.position.Y - self.height + 4; - self.width - // orig(self); } } orig(self); }
private void PlatformCollision(On.Terraria.Player.orig_Update_NPCCollision orig, Player self) { // TODO this needs synced somehow if (self.controlDown) { self.GetModPlayer <StarlightPlayer>().platformTimer = 5; } if (self.controlDown || self.GetModPlayer <StarlightPlayer>().platformTimer > 0 || self.GoingDownWithGrapple) { orig(self); return; } foreach (NPC npc in Main.npc) { if (!npc.active || npc.modNPC == null || !(npc.modNPC is MovingPlatform)) { continue; } Rectangle playerRect = new Rectangle((int)self.position.X, (int)self.position.Y + (self.height), self.width, 1); Rectangle npcRect = new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, 8 + (self.velocity.Y > 0 ? (int)self.velocity.Y : 0)); if (playerRect.Intersects(npcRect) && self.position.Y <= npc.position.Y) { if (!self.justJumped && self.velocity.Y >= 0) { self.gfxOffY = npc.gfxOffY; self.velocity.Y = 0; self.fallStart = (int)(self.position.Y / 16f); self.position.Y = npc.position.Y - self.height + 4; orig(self); } } } var mp = self.GetModPlayer <GravityPlayer>(); if (mp.controller != null && mp.controller.npc.active) { self.velocity.Y = 0; } orig(self); }
internal static void SolidTopCollision(On.Terraria.Player.orig_Update_NPCCollision orig, Player self) { var modSelf = self.GetModPlayer <CollideableNPCPlayer>(); if (self.grappling[0] < 0) { modSelf.platformDropTimer--; if (self.controlDown && modSelf.platformTimer >= 6) { modSelf.platformDropTimer = 8; } bool success = false; for (int i = 0; i < Main.maxNPCs; ++i) { NPC npc = Main.npc[i]; if (!npc.active || npc.modNPC == null || !(npc.modNPC is ISolidTopNPC) || (npc.whoAmI == modSelf.platformWhoAmI && modSelf.platformDropTimer > 0)) { continue; } var playerBox = new Rectangle((int)self.position.X, (int)self.position.Y + self.height, self.width, 1); var floorBox = new Rectangle((int)npc.position.X, (int)npc.position.Y - (int)npc.velocity.Y, npc.width, 8 + (int)Math.Max(self.velocity.Y, 0)); if (playerBox.Intersects(floorBox) && self.velocity.Y > 0 && !Collision.SolidCollision(self.Bottom, self.width, (int)Math.Max(1 + npc.velocity.Y, 0))) { self.gfxOffY = npc.gfxOffY; self.position.Y = npc.position.Y - self.height + 4; self.velocity.Y = 0; self.fallStart = (int)(self.position.Y / 16f); if (self == Main.LocalPlayer) { NetMessage.SendData(MessageID.PlayerControls, -1, -1, null, Main.LocalPlayer.whoAmI); } if (modSelf.platformTimer < 0) { modSelf.platformTimer = -1; } modSelf.platformTimer++; modSelf.platformWhoAmI = npc.whoAmI; orig(self); success = true; break; } } if (!success && modSelf.platformDropTimer <= 0) { modSelf.platformTimer--; modSelf.platformWhoAmI = -1; } } orig(self); }