Files
zzz_REBIRTH__Utils/Scripts/Dialog/NPCs/DialogActionNPCActionRebirth.cs
2025-06-04 16:44:53 +09:30

217 lines
11 KiB
C#

//using static RebirthManager;
public class DialogActionNPCActionRebirth : BaseDialogAction
{
public override void PerformAction(EntityPlayer player)
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction START, ID: " + ID);
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(player as EntityPlayerLocal);
if (!string.IsNullOrEmpty(ID))
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 1");
EntityNPCRebirth entityNPC = (EntityNPCRebirth)uiforPlayer.xui.Dialog.Respondent;
if (entityNPC != null)
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 2");
if (!string.IsNullOrEmpty(ID))
{
bool checkControl = false;
//Log.Out("DialogActionNPCActionRebirth-PerformAction 3");
if (ID.ToLower() == "stay")
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 4");
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient)
{
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageSetGuardPositionRebirth>().Setup(entityNPC.entityId, entityNPC.entityId), false);
}
else
{
entityNPC.guardPosition = entityNPC.position;
entityNPC.bWillRespawn = true;
entityNPC.guardLookPosition = entityNPC.position + entityNPC.GetLookVector();
}
entityNPC.SetRevengeTarget((EntityAlive) null);
entityNPC.attackTarget = (EntityAlive) null;
entityNPC.motion = Vector3.zero;
entityNPC.navigator?.clearPath();
entityNPC.moveHelper?.Stop();
entityNPC.speedForward = 0;
entityNPC.speedStrafe = 0;
//entityNPC.motion = Vector3.zero;
//entityNPC.navigator?.clearPath();
//entityNPC.moveHelper?.Stop();
//Log.Out("DialogActionNPCActionRebirth-PerformAction SET TO STAY");
entityNPC.Buffs.SetCustomVar("CurrentOrder", (int)EntityUtilities.Orders.Stay);
entityNPC.Buffs.SetCustomVar("onMission", 0f);
checkControl = true;
RebirthManager.UpdateHireInfo(entityNPC.entityId, "order", "stay", entityNPC.position.ToString(), entityNPC.rotation.ToString());
player.Companions.Remove(entityNPC);
}
else if (ID.ToLower() == "follow")
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 5");
//entityNPC.Buffs.SetCustomVar("$FR_NPC_Respawn", 0f);
entityNPC.SetRevengeTarget((EntityAlive) null);
entityNPC.attackTarget = (EntityAlive) null;
entityNPC.guardPosition = Vector3.zero;
entityNPC.motion = Vector3.zero;
entityNPC.navigator?.clearPath();
entityNPC.moveHelper?.Stop();
entityNPC.speedForward = 0;
entityNPC.speedStrafe = 0;
//entityNPC.motion = Vector3.zero;
//entityNPC.navigator?.clearPath();
//entityNPC.moveHelper?.Stop();
//Log.Out("DialogActionNPCActionRebirth-PerformAction SET TO FOLLOW");
entityNPC.HideNPC(false);
entityNPC.Buffs.SetCustomVar("CurrentOrder", (int)EntityUtilities.Orders.Follow);
entityNPC.Buffs.SetCustomVar("onMission", 0f);
entityNPC.Buffs.RemoveBuff("FuriousRamsayBuffPauseAttack");
checkControl = true;
RebirthManager.UpdateHireInfo(entityNPC.entityId, "order", "follow");
entityNPC.LeaderUtils.AddCompanion();
}
else if (ID.ToLower() == "guard")
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 6");
//Log.Out("DialogActionNPCActionRebirth-PerformAction player.position: " + player.position);
//Log.Out("DialogActionNPCActionRebirth-PerformAction entityNPC.guardPosition: " + entityNPC.guardPosition);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient)
{
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageSetGuardPositionRebirth>().Setup(entityNPC.entityId, player.entityId), false);
}
else
{
entityNPC.guardPosition = EntityUtilities.CenterPosition(player.position);
entityNPC.bWillRespawn = true;
entityNPC.guardLookPosition = player.position + player.GetLookVector();
}
entityNPC.SetRevengeTarget((EntityAlive) null);
entityNPC.attackTarget = (EntityAlive) null;
entityNPC.motion = Vector3.zero;
entityNPC.navigator?.clearPath();
entityNPC.moveHelper?.Stop();
entityNPC.speedForward = 0;
entityNPC.speedStrafe = 0;
//Log.Out("DialogActionNPCActionRebirth-PerformAction SET TO STAY (GUARD)");
entityNPC.Buffs.SetCustomVar("CurrentOrder", (int)EntityUtilities.Orders.Stay);
entityNPC.Buffs.SetCustomVar("onMission", 0f);
checkControl = true;
RebirthManager.UpdateHireInfo(entityNPC.entityId, "order", "guard", player.position.ToString(), player.rotation.ToString());
player.Companions.Remove(entityNPC);
}
else if (ID.ToLower() == "pickup")
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7");
var playerInventory = uiforPlayer.xui.PlayerInventory;
if (playerInventory == null)
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7a");
return;
}
EntityNPCRebirth myEntity = GameManager.Instance.World.GetEntity(entityNPC.entityId) as EntityNPCRebirth;
if (myEntity != null)
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7b");
if (myEntity.EntityClass.Properties.Values.ContainsKey("SpawnBlock"))
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7c");
string itemName = "FuriousRamsaySpawnCube" + myEntity.EntityClass.Properties.Values["SpawnBlock"] + "_PickedUp";
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7d, itemName: " + itemName);
ItemValue item = ItemClass.GetItem(itemName);
if (item != null)
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7e");
var itemValue = myEntity.GetItemValue(item);
var itemStack = new ItemStack(itemValue, 1);
if (!playerInventory.AddItem(itemStack))
{
if (!player.inventory.AddItem(itemStack))
{
if (!player.bag.AddItem(itemStack))
{
return;
}
}
}
//Log.Out("DialogActionNPCActionRebirth-PerformAction IsServer: " + SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer);
EntityUtilities.CollectEntityServer(myEntity.entityId, player.entityId);
RebirthUtilities.DespawnEntity(myEntity);
//player.Companions.Remove(entityNPC);
/*GameManager.Instance.DropContentOfLootContainerServer(BlockValue.Air, new Vector3i(myEntity.position), myEntity.entityId);
RebirthManager.RemoveHire(myEntity.entityId);
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7g");
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageDespawnEntityRebirth>().Setup(myEntity.entityId), false);
}
else
{
//Log.Out("DialogActionNPCActionRebirth-PerformAction 7h");
myEntity.bWillRespawn = false;
GameManager.Instance.World.RemoveEntity(myEntity.entityId, EnumRemoveEntityReason.Unloaded);
}*/
}
}
}
}
if (checkControl)
{
float flMode = player.Buffs.GetCustomVar("varNPCModMode");
float flHalt = player.Buffs.GetCustomVar("varNPCModStopAttacking");
if (flMode == 0)
{
entityNPC.Buffs.AddBuff("buffNPCModFullControlMode");
}
else
{
entityNPC.Buffs.RemoveBuff("buffNPCModFullControlMode");
}
if (flHalt == 1)
{
entityNPC.Buffs.AddBuff("buffNPCModStopAttacking");
}
else
{
entityNPC.Buffs.RemoveBuff("buffNPCModStopAttacking");
}
}
}
}
return;
}
}
}