public override void MouseUp(UIMouseEvent evt) { base.MouseUp(evt); // only care about mouse-ups in the click + drag action after selecting a buff if(clickedBuffIdx == -1) { return; } // should probably read this from TacticsPlayer but that's a bit clunky MinionTacticsPlayer myPlayer = Main.player[Main.myPlayer].GetModPlayer<MinionTacticsPlayer>(); int buffType = myPlayer.player.buffType[clickedBuffIdx]; clickedBuffIdx = -1; float mouseY = evt.MousePosition.Y; float startY = Top.Pixels + dropDown.Top.Pixels; // don't trigger if not within vertical bounds (any horizontal pos is fine) if (mouseY < startY || mouseY > startY + dropDown.Height.Pixels) { return; } float regionHeight = dropDown.Height.Pixels / (MinionTacticsPlayer.TACTICS_GROUPS_COUNT - 1); int region = (int)((mouseY - startY) / regionHeight); myPlayer.SetGroupForMinion(region, buffType); UnsetSelected(); }
public Vector2?PlayerTargetPosition(float maxRange, Vector2?centeredOn = null, float noLOSRange = 0, Vector2?losCenter = null) { MinionTacticsPlayer tacticsPlayer = player.GetModPlayer <MinionTacticsPlayer>(); if (tacticsPlayer.IgnoreVanillaMinionTarget > 0 && tacticsPlayer.SelectedTactic != TargetSelectionTacticHandler.GetTactic <ClosestEnemyToMinion>()) { return(null); } Vector2 center = centeredOn ?? projectile.Center; Vector2 losCenterVector = losCenter ?? projectile.Center; if (player.HasMinionAttackTargetNPC) { NPC npc = Main.npc[player.MinionAttackTargetNPC]; // fix to prevent certain minions from continually stacking debuffs against // a single enemy if (ShouldIgnoreNPC(npc)) { return(null); } float distance = Vector2.Distance(npc.Center, center); if (distance < noLOSRange || (distance < maxRange && Collision.CanHitLine(losCenterVector, 1, 1, npc.position, npc.width, npc.height))) { targetNPCIndex = player.MinionAttackTargetNPC; return(npc.Center); } } return(null); }
public SyncMinionTacticsPlayerPacket(MinionTacticsPlayer player) : base(player.player) { tacticsIds = player.TacticsIDs; selectedTactic = (byte)player.CurrentTacticGroup; tacticsMap = player.MinionTacticsMap; ignoreTargetReticle = player.IgnoreVanillaMinionTarget; }
/// <summary> /// This gets called each time the dropdown moves to a new minion buff /// </summary> /// <param name="id">Tactic ID</param> internal override void StartShowing() { base.StartShowing(); MinionTacticsPlayer tacticsPlayer = Main.player[Main.myPlayer].GetModPlayer <MinionTacticsPlayer>(); for (int i = 0; i < buttons.Count; i++) { buttons[i].Highlighted = tacticsPlayer.CurrentTacticGroup == i; } }
/// <summary> /// This gets called each time the dropdown moves to a new minion buff /// </summary> /// <param name="id">Tactic ID</param> internal void SetSelected(int buffId) { currentBuffId = buffId; MinionTacticsPlayer tacticsPlayer = Main.player[Main.myPlayer].GetModPlayer <MinionTacticsPlayer>(); int tacticIdx = tacticsPlayer.GetGroupForBuff(buffId); framesUntilHide = 180; foreach (var button in buttons) { bool selected = button.index == tacticIdx; button.SetSelected(selected); } }
protected override void PostReceive(BinaryReader reader, int sender, Player player) { MinionTacticsPlayer minionTacticsPlayer = player.GetModPlayer <MinionTacticsPlayer>(); byte[] tacticsIds = reader.ReadBytes(MinionTacticsPlayer.TACTICS_GROUPS_COUNT); byte selectedTactic = reader.ReadByte(); byte ignoreTargetReticle = reader.ReadByte(); // reading rest of packet directly into dict MinionTacticsGroupMapper.ReadBuffMap(reader, minionTacticsPlayer.MinionTacticsMap); minionTacticsPlayer.SetAllTactics(tacticsIds, selectedTactic); minionTacticsPlayer.IgnoreVanillaMinionTarget = ignoreTargetReticle; }
protected override void PostReceive(BinaryReader reader, int sender, Player player) { MinionTacticsGroupMapper.ReadBuffMap(reader, out Dictionary <int, int> destDict); MinionTacticsPlayer modPlayer = player.GetModPlayer <MinionTacticsPlayer>(); foreach (var pair in destDict) { modPlayer.MinionTacticsMap[pair.Key] = pair.Value; } // TODO pass the raw byte array, rather than deconstructing/reconstructing the dest dict if (Main.netMode == NetmodeID.Server) { new MinionGroupsPacket(player, destDict).Send(from: sender); } }
protected override void DrawSelf(SpriteBatch spriteBatch) { base.DrawSelf(spriteBatch); // draw a little icon in the bottem left corner the current tactic for the given group MinionTacticsPlayer tacticsPlayer = Main.player[Main.myPlayer].GetModPlayer <MinionTacticsPlayer>(); byte tacticsId = tacticsPlayer.TacticsIDs[index]; Texture2D tacticSmallTexture = TargetSelectionTacticHandler.SmallTextures[tacticsId]; CalculatedStyle dimensions = GetDimensions(); float scale = 0.75f; Vector2 bottomLeft = new Vector2(dimensions.X, dimensions.Y + dimensions.Height); Vector2 tacticPosition = bottomLeft - new Vector2(0, tacticSmallTexture.Height * scale); Color color = Color.White * (InHoverState || selected ? 1 : 0.7f); spriteBatch.Draw(tacticSmallTexture, tacticPosition, null, color, 0f, Vector2.Zero, scale, 0f, 0f); }
internal void SetupPathfinderMetas() { // these values don't like being initialized in Initialize() for some reason myTacticsPlayer = player.GetModPlayer <MinionTacticsPlayer>(); pathfinderMetas = new PathfinderMetadata[MinionTacticsPlayer.TACTICS_GROUPS_COUNT]; for (int i = 0; i < MinionTacticsPlayer.TACTICS_GROUPS_COUNT; i++) { pathfinderMetas[i] = new PathfinderMetadata(this, i); } for (int i = 0; i < Main.maxPlayers; i++) { Player p = Main.player[i]; if (p.active) { MinionPathfindingPlayer pathPlayer = p.GetModPlayer <MinionPathfindingPlayer>(); } } }
public override void OnInitialize() { base.OnInitialize(); // depending on the order of children for setup like this is iffy, but relatively efficient for (int i = 0; i < MinionTacticsPlayer.TACTICS_GROUPS_COUNT; i++) { int localI = i; buttons[i].OnLeftClick = () => { MinionTacticsPlayer tacticsPlayer = Main.player[Main.myPlayer].GetModPlayer <MinionTacticsPlayer>(); tacticsPlayer.SetTacticsGroup(localI); for (int j = 0; j < MinionTacticsPlayer.TACTICS_GROUPS_COUNT; j++) { buttons[j].Highlighted = tacticsPlayer.CurrentTacticGroup == j; } StopShowing(); }; } buttons[MinionTacticsPlayer.TACTICS_GROUPS_COUNT].OnLeftClick = () => { // remove every waypoint, lack of ability to remove individual ones is a bit annoying // but less annoying than having to click multiple times to remove a single waypoint MinionTacticsPlayer tacticsPlayer = Main.player[Main.myPlayer].GetModPlayer <MinionTacticsPlayer>(); MinionPathfindingPlayer waypointPlayer = Main.player[Main.myPlayer].GetModPlayer <MinionPathfindingPlayer>(); int oldGroup = tacticsPlayer.CurrentTacticGroup; tacticsPlayer.CurrentTacticGroup = MinionTacticsPlayer.TACTICS_GROUPS_COUNT - 1; waypointPlayer.ToggleWaypoint(true); tacticsPlayer.CurrentTacticGroup = oldGroup; for (int j = 0; j < MinionTacticsPlayer.TACTICS_GROUPS_COUNT; j++) { buttons[j].Highlighted = false; } buttons.Last().Highlighted = true; StopShowing(); }; // all buttons have the same left and right click for (int i = 0; i < buttons.Count; i++) { buttons[i].OnRightClick = buttons[i].OnLeftClick; } }
public override void MouseDown(UIMouseEvent evt) { // another menu is open, so don't check if(Main.ingameOptionsWindow || Main.playerInventory || (dropDown.framesUntilHide > 0 && dropDown.ContainsPoint(evt.MousePosition))) { return; } clickedBuffIdx = GetClickedBuffIdx(evt); if(clickedBuffIdx == -1) { return; } MinionTacticsPlayer myPlayer = Main.player[Main.myPlayer].GetModPlayer<MinionTacticsPlayer>(); int buffType = myPlayer.player.buffType[clickedBuffIdx]; if(myPlayer.GroupIsSetForMinion(buffType)) { Vector2 buffTop = GetBuffTopLeft(clickedBuffIdx); dropDown.Left.Pixels = xMin + buffTop.X - dropDown.Width.Pixels/2 + Main.buffTexture[buffType].Width/2; dropDown.Top.Pixels = buffTop.Y + 38; dropDown.SetSelected(buffType); } }
internal void DrawBuffOverlays(SpriteBatch spriteBatch) { // another menu is open, so don't draw overlays if(Main.ingameOptionsWindow || Main.playerInventory) { return; } Vector2 topCorner = new Vector2(xMin, yMin); float scale = 1; MinionTacticsPlayer myPlayer = Main.player[Main.myPlayer].GetModPlayer<MinionTacticsPlayer>(); for(int i = 0; i < myPlayer.player.CountBuffs(); i++) { int buffType = myPlayer.player.buffType[i]; if(myPlayer.GroupIsSetForMinion(buffType)) { int groupIdx = myPlayer.GetGroupForBuff(buffType); Vector2 drawPos = topCorner + GetBuffTopLeft(i); Texture2D texture = TargetSelectionTacticHandler.GroupOverlayTextures[groupIdx]; spriteBatch.Draw(texture, drawPos, null, Color.White, 0f, Vector2.Zero, scale, 0f, 0f); } } }