public static void UponPickingOption(Option option, PlayerMod player, List<Option> LastPickedOptions) { TerraGuardian[] Guardians = player.GetAllGuardianFollowers; switch (option.oType) { case Option.OptionType.Order: case Option.OptionType.Action: case Option.OptionType.Item: case Option.OptionType.Interaction: case Option.OptionType.PullGuardians: { AddOptionHolder(); AddOption(Option.OptionType.PickGuardian, true, 255); for (int i = 0; i < Guardians.Length; i++) { if (!Guardians[i].Active) continue; if (i == 0 && player.ControllingGuardian) continue; AddOption(Option.OptionType.PickGuardian, true, i); } } break; case Option.OptionType.SwitchGroup: { AddOptionHolder(); for(int i = 0; i < 255; i++) { if(Main.player[i].active && i != Main.myPlayer) { AddOption(Option.OptionType.PickTeam, true, i); } } } break; case Option.OptionType.Tactic: { AddOptionHolder(); AddOption(Option.OptionType.ChargeOnTarget); AddOption(Option.OptionType.AvoidContactWithTarget); AddOption(Option.OptionType.AttackTargetFromAwayIt); AddOption(Option.OptionType.FreeWill); } break; case Option.OptionType.PickTeam: { PlayerMod.ChangeSelectedGroup(option.InternalValue); Close(); } break; case Option.OptionType.PickGuardian: { SelectedGuardian = (byte)option.InternalValue; switch (LastPickedOptions[0].oType) { case Option.OptionType.Order: { AddOptionHolder(); AddOption(Option.OptionType.Follow); AddOption(Option.OptionType.WaitHere); AddOption(Option.OptionType.GuardHere); AddOption(Option.OptionType.GoAheadBehind); AddOption(Option.OptionType.AvoidCombat); } break; case Option.OptionType.Action: { AddOptionHolder(); AddOption(Option.OptionType.GoSellLoot, ((SelectedGuardian == 255 && Guardians.Any(x => x.Active && x.HasFlag(GuardianFlags.MayGoSellLoot))) || (SelectedGuardian < 255 && Guardians[SelectedGuardian].HasFlag(GuardianFlags.MayGoSellLoot)))); AddOption(Option.OptionType.UseFurniture); AddOption(Option.OptionType.LiftMe); AddOption(Option.OptionType.LaunchMe, player.player.wings > 0); AddOption(Option.OptionType.FreeControl, (SelectedGuardian == 255 && Guardians.Any(x => x.Active && x.PlayerMounted && x.HasFlag(GuardianFlags.StopMindingAfk))) || (SelectedGuardian != 255 && Guardians[SelectedGuardian].PlayerMounted && Guardians[SelectedGuardian].HasFlag(GuardianFlags.StopMindingAfk))); } break; case Option.OptionType.Item: { AddOptionHolder(); AddOption(Option.OptionType.HealSelf); AddOption(Option.OptionType.UseBuffPotions); AddOption(Option.OptionType.UseSkillResetPotion); AddOption(Option.OptionType.UseStatusIncreaseItem); } break; case Option.OptionType.Interaction: { AddOptionHolder(); AddOption(Option.OptionType.MountGuardian, (SelectedGuardian == 255 && Guardians.Any(x => x.Active && (x.HasFlag(GuardianFlags.AllowMount) || x.PlayerMounted))) || (SelectedGuardian != 255 && (Guardians[SelectedGuardian].HasFlag(GuardianFlags.AllowMount) || Guardians[SelectedGuardian].PlayerMounted))); AddOption(Option.OptionType.ShareMount, player.player.mount.Active && (SelectedGuardian == 255 || (!player.GetAllGuardianFollowers[SelectedGuardian].PlayerControl && !player.GetAllGuardianFollowers[SelectedGuardian].HasFlag(GuardianFlags.DisableMountSharing)))); AddOption(Option.OptionType.TeleportWithPlayer, ((SelectedGuardian == 255 && Main.player[Main.myPlayer].GetModPlayer<PlayerMod>().GetAllGuardianFollowers.Any(x => x.Active && x.HasMagicMirror)) || (SelectedGuardian != 255 && Main.player[Main.myPlayer].GetModPlayer<PlayerMod>().GetAllGuardianFollowers[SelectedGuardian].HasMagicMirror))); AddOption(Option.OptionType.PlayerControl, !player.IsCompanionParty && ( (SelectedGuardian == 255 && Guardians.Any(x => x.Active && x.HasFlag(GuardianFlags.PlayerControl))) || (SelectedGuardian < 255 && Guardians[SelectedGuardian].Active && Guardians[SelectedGuardian].HasFlag(GuardianFlags.PlayerControl)))); AddOption(Option.OptionType.SetLeader, SelectedGuardian != 0 && SelectedGuardian != 255 && !player.ControllingGuardian); } break; case Option.OptionType.PullGuardians: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander) { guardians[g].BePulledByPlayer(); } } Close(); } break; } } break; case Option.OptionType.Follow: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander) { guardians[g].GuardingPosition = null; } } Close(); } break; case Option.OptionType.WaitHere: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; Point GuardPosition = new Point((int)player.player.Center.X / 16, (int)(player.player.position.Y + player.player.height - 1) / 16); for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerMounted) { guardians[g].GuardingPosition = GuardPosition; guardians[g].IsGuardingPlace = false; } } Close(); } break; case Option.OptionType.GuardHere: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; Point GuardPosition = new Point((int)player.player.Center.X / 16, (int)(player.player.position.Y + player.player.height - 1) / 16); for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerMounted) { guardians[g].GuardingPosition = GuardPosition; guardians[g].IsGuardingPlace = true; } } Close(); } break; case Option.OptionType.GoAheadBehind: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander) { guardians[g].ChargeAhead = !guardians[g].ChargeAhead; } } Close(); } break; case Option.OptionType.AvoidCombat: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander) { guardians[g].AvoidCombat = !guardians[g].AvoidCombat; } } Close(); } break; case Option.OptionType.FreeControl: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; byte HighestPriority = 0; TerraGuardian MountedPriority = null; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && guardians[g].PlayerMounted && guardians[g].HasFlag(GuardianFlags.StopMindingAfk)) { byte Priority = 0; if (guardians[g].ReverseMount) { Priority = 1; } else { Priority = 2; } if (Priority > HighestPriority) { MountedPriority = guardians[g]; HighestPriority = Priority; } } } if (MountedPriority != null) { MountedPriority.ToggleGuardianFullControl(!MountedPriority.GuardianHasControlWhenMounted); } Close(); } break; case Option.OptionType.GoSellLoot: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && guardians[g].HasFlag(GuardianFlags.MayGoSellLoot) && !guardians[g].PlayerControl) { GuardianActions.SellLootCommand(guardians[g]); } } Close(); } break; case Option.OptionType.TeleportWithPlayer: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerControl) { if (GuardianActions.TeleportWithPlayerCommand(guardians[g], player.player)) break; } } Close(); } break; case Option.OptionType.UseFurniture: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander) { if (guardians[g].furniturex != -1) { guardians[g].LeaveFurniture(); } else { guardians[g].UseNearbyFurniture(); } } } Close(); } break; case Option.OptionType.LiftMe: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerControl) { if (GuardianActions.UseLiftPlayer(guardians[g], Main.player[guardians[g].OwnerPos])) break; } } Close(); } break; case Option.OptionType.LaunchMe: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerControl) { GuardianActions.UseLaunchPlayer(guardians[g], Main.player[guardians[g].OwnerPos]); } } Close(); } break; case Option.OptionType.HealSelf: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerControl) { guardians[g].AttemptToUseHealingPotion(); } } Close(); } break; case Option.OptionType.UseBuffPotions: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerControl) { GuardianActions.UseBuffPotions(guardians[g]); } } Close(); } break; case Option.OptionType.UseSkillResetPotion: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander) { GuardianActions.UseSkillResetPotionCommand(guardians[g]); } } Close(); } break; case Option.OptionType.UseStatusIncreaseItem: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerControl) { GuardianActions.UseStatusIncreaseItems(guardians[g]); } } Close(); } break; case Option.OptionType.MountGuardian: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; bool Dismount = player.MountedOnGuardian || player.GuardianMountingOnPlayer; bool SomeoneMounted = player.GuardianMountingOnPlayer, MountedOnGuardian = player.MountedOnGuardian; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && guardians[g].HasFlag(GuardianFlags.AllowMount) && !guardians[g].PlayerControl) { if (SelectedGuardian == 255) { if (guardians[g].PlayerMounted) { if (Dismount) { GuardianActions.GuardianPutPlayerOnTheFloorCommand(guardians[g]); } } else { if (!Dismount) { if (GuardianActions.GuardianPutPlayerOnShoulderCommand(guardians[g])) break; } } } else { if (guardians[g].PlayerMounted) { GuardianActions.GuardianPutPlayerOnTheFloorCommand(guardians[g]); } else { if (!guardians[g].ReverseMount) { if (!MountedOnGuardian) { if (GuardianActions.GuardianPutPlayerOnShoulderCommand(guardians[g])) break; } } else if (!SomeoneMounted) { if (GuardianActions.GuardianPutPlayerOnShoulderCommand(guardians[g])) break; } } } } } Close(); } break; case Option.OptionType.ShareMount: { TerraGuardian[] guardians = player.GetAllGuardianFollowers; for (int g = 0; g < guardians.Length; g++) { if ((SelectedGuardian == 255 || g == SelectedGuardian) && guardians[g].Active && !guardians[g].IsCommander && !guardians[g].PlayerControl) { if (guardians[g].SittingOnPlayerMount) guardians[g].DoSitOnPlayerMount(false); else GuardianActions.GuardianJoinPlayerMountCommand(guardians[g], Main.player[guardians[g].OwnerPos]); } } Close(); } break; case Option.OptionType.PlayerControl: { if (player.Guardian.Active && player.Guardian.HasFlag(GuardianFlags.PlayerControl)) { player.Guardian.TogglePlayerControl(); } Close(); } break; case Option.OptionType.SetLeader: { player.ChangeLeaderGuardian(SelectedGuardian); Close(); } break; case Option.OptionType.ChargeOnTarget: { player.CurrentTactic = PlayerMod.BehaviorChanges.ChargeOnTarget; Close(); } break; case Option.OptionType.AvoidContactWithTarget: { player.CurrentTactic = PlayerMod.BehaviorChanges.AvoidContact; Close(); } break; case Option.OptionType.AttackTargetFromAwayIt: { player.CurrentTactic = PlayerMod.BehaviorChanges.StayAwayFromTarget; Close(); } break; case Option.OptionType.FreeWill: { player.CurrentTactic = PlayerMod.BehaviorChanges.FreeWill; Close(); } break; } }
public static void ExecuteAction(Orders o) { Action <TerraGuardian> action = delegate(TerraGuardian g) { }; bool MainGuardianOrder = (o == Orders.Mount && SpecificGuardian == 255) || o == Orders.PlayerControl; bool SomeoneExecutedAction = false; switch (o) { case Orders.Mount: action = delegate(TerraGuardian g) { //Guardian.ToggleMount(); if (g.PlayerMounted) { GuardianActions.GuardianPutPlayerOnTheFloorCommand(g); //Guardian.ToggleMount(); } else { if (g.HasFlag(GuardianFlags.AllowMount) && GuardianActions.GuardianPutPlayerOnShoulderCommand(g)) { SomeoneExecutedAction = true; } } }; break; case Orders.FollowWait: action = delegate(TerraGuardian g) { g.ToggleWait(); }; break; case Orders.HealSelf: action = delegate(TerraGuardian g) { if (g.HP < g.MHP * 0.7f) { g.AttemptToUseHealingPotion(); } }; break; case Orders.AvoidCombat: action = delegate(TerraGuardian g) { g.AvoidCombat = !g.AvoidCombat; }; break; case Orders.GoAhead: action = delegate(TerraGuardian g) { g.ChargeAhead = !g.ChargeAhead; }; break; case Orders.CallToPosition: action = delegate(TerraGuardian g) { g.BePulledByPlayer(); }; break; case Orders.PlayerControl: action = delegate(TerraGuardian g) { if (g.HasFlag(GuardianFlags.PlayerControl)) { g.TogglePlayerControl(); } }; break; case Orders.LaunchMe: action = delegate(TerraGuardian g) { if (GuardianActions.UseLaunchPlayer(g, Main.player[g.OwnerPos])) { SomeoneExecutedAction = true; } }; break; case Orders.LiftMe: action = delegate(TerraGuardian g) { if (GuardianActions.UseLiftPlayer(g, Main.player[g.OwnerPos])) { SomeoneExecutedAction = true; } }; break; case Orders.UseBuffPotions: action = delegate(TerraGuardian g) { GuardianActions.UseBuffPotions(g); }; break; case Orders.GoSellLoot: action = delegate(TerraGuardian g) { if (g.HasFlag(GuardianFlags.MayGoSellLoot)) { GuardianActions.SellLootCommand(g); } }; break; case Orders.JoinMyMount: action = delegate(TerraGuardian g) { GuardianActions.GuardianJoinPlayerMountCommand(g, Main.player[g.OwnerPos]); }; break; case Orders.GetOffMyMount: action = delegate(TerraGuardian g) { if (g.SittingOnPlayerMount) { g.DoSitOnPlayerMount(false); g.Position.X = Main.player[g.OwnerPos].position.X + Main.player[g.OwnerPos].width * 0.5f; g.Position.Y = Main.player[g.OwnerPos].position.Y + Main.player[g.OwnerPos].height - 1; } }; break; case Orders.TeleportWithPlayerToTown: action = delegate(TerraGuardian g) { if (GuardianActions.TeleportWithPlayerCommand(g, Main.player[g.OwnerPos])) { SomeoneExecutedAction = true; } }; break; case Orders.UseSkillResetPotion: action = delegate(TerraGuardian g) { GuardianActions.UseSkillResetPotionCommand(g); }; break; case Orders.TestFurnitureOrder: action = delegate(TerraGuardian g) { if (g.furniturex > -1 || g.furniturey > -1) { g.LeaveFurniture(); } else { g.UseNearbyFurniture(9, ushort.MaxValue, true); } }; break; case Orders.GiveGuardianControl: action = delegate(TerraGuardian g) { if (g.HasFlag(GuardianFlags.StopMindingAfk)) { g.ToggleGuardianFullControl(!g.GuardianHasControlWhenMounted); } }; break; case Orders.UseStatusIncreaseItems: action = delegate(TerraGuardian g) { if (!g.DoAction.InUse) { GuardianActions.UseStatusIncreaseItems(g); } }; break; case Orders.OrderAllGuardians: SpecificGuardian = 255; RefreshOrders(); break; case Orders.OrderMainGuardian: SpecificGuardian = 0; RefreshOrders(); break; case Orders.OrderFirstAssistGuardian: SpecificGuardian = 1; RefreshOrders(); break; case Orders.OrderSecondAssistGuardian: SpecificGuardian = 2; RefreshOrders(); break; case Orders.OrderThirdAssistGuardian: SpecificGuardian = 3; RefreshOrders(); break; case Orders.OrderFourthAssistGuardian: SpecificGuardian = 4; RefreshOrders(); break; } PlayerMod player = Main.player[Guardian.OwnerPos].GetModPlayer <PlayerMod>(); if (MainGuardianOrder) { if (player.Guardian.Active) { action(player.Guardian); } } else if (SpecificGuardian == 255) { foreach (TerraGuardian g in Main.player[Guardian.OwnerPos].GetModPlayer <PlayerMod>().GetAllGuardianFollowers.Where(x => x.Active && !x.Downed)) { action(g); if (SomeoneExecutedAction) { break; } } } else { if (SpecificGuardian == 0) { if (player.Guardian.Active) { action(player.Guardian); } } else { if (SpecificGuardian - 1 >= 0 && SpecificGuardian - 1 < MainMod.MaxExtraGuardianFollowers) { TerraGuardian guardian = player.AssistGuardians[SpecificGuardian - 1]; if (guardian.Active) { action(guardian); } } } } }