Files
zzz_REBIRTH__Utils/Scripts/Quests/ObjectiveGotoRandomSDX.cs
2025-06-04 16:44:53 +09:30

327 lines
14 KiB
C#

using System.Globalization;
public class ObjectiveGotoRandomSDX : BaseObjective
{
public override BaseObjective.ObjectiveValueTypes ObjectiveValueType
{
get
{
return BaseObjective.ObjectiveValueTypes.Distance;
}
}
public override void SetupObjective()
{
this.keyword = Localization.Get("ObjectiveRallyPointHeadTo");
this.SetupIcon();
}
public override bool UpdateUI
{
get
{
return base.ObjectiveState != BaseObjective.ObjectiveStates.Failed;
}
}
public override void SetupDisplay()
{
base.Description = this.keyword;
this.StatusText = "";
}
public override string StatusText
{
get
{
if (base.OwnerQuest.CurrentState == Quest.QuestState.InProgress)
{
return ValueDisplayFormatters.Distance(this.distance);
}
if (base.OwnerQuest.CurrentState == Quest.QuestState.NotStarted)
{
return "";
}
if (base.ObjectiveState == BaseObjective.ObjectiveStates.Failed)
{
return Localization.Get("failed");
}
return Localization.Get("completed");
}
}
public override void AddHooks()
{
QuestEventManager.Current.AddObjectiveToBeUpdated(this);
base.OwnerQuest.HandleMapObject(Quest.PositionDataTypes.Location, this.NavObjectName, -1);
}
public override void RemoveHooks()
{
QuestEventManager.Current.RemoveObjectiveToBeUpdated(this);
}
protected virtual void SetupIcon()
{
}
protected virtual Vector3 GetPosition()
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition START");
//Log.Out("ObjectiveGotoRandomSDX-GetPosition this.position.x: " + this.position.x);
//Log.Out("ObjectiveGotoRandomSDX-GetPosition this.position.y: " + this.position.y);
//Log.Out("ObjectiveGotoRandomSDX-GetPosition this.position.z: " + this.position.z);
if (base.OwnerQuest.GetPositionData(out this.position, Quest.PositionDataTypes.Location))
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition 1");
base.OwnerQuest.Position = this.position;
this.positionSet = true;
base.OwnerQuest.HandleMapObject(Quest.PositionDataTypes.Location, this.NavObjectName, -1);
base.CurrentValue = 2;
return this.position;
}
if (base.OwnerQuest.GetPositionData(out this.position, Quest.PositionDataTypes.TreasurePoint))
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition 2");
this.positionSet = true;
base.OwnerQuest.SetPositionData(Quest.PositionDataTypes.Location, base.OwnerQuest.Position);
base.OwnerQuest.HandleMapObject(Quest.PositionDataTypes.Location, this.NavObjectName, -1);
base.CurrentValue = 2;
return this.position;
}
EntityPlayer ownerPlayer = base.OwnerQuest.OwnerJournal.OwnerPlayer;
float num = 50f;
if (base.Value != null && base.Value != "" && !StringParsers.TryParseFloat(base.Value, out num, 0, -1, NumberStyles.Any) && base.Value.Contains("-"))
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition 3");
string[] array = base.Value.Split(new char[]
{
'-'
});
float num2 = StringParsers.ParseFloat(array[0], 0, -1, NumberStyles.Any);
float num3 = StringParsers.ParseFloat(array[1], 0, -1, NumberStyles.Any);
num = GameManager.Instance.World.GetGameRandom().RandomFloat * (num3 - num2) + num2;
}
//Log.Out("ObjectiveGotoRandomSDX-GetPosition Instance.IsServer: " + SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition 4");
Vector3i vector3i = ObjectiveGotoRandomSDX.CalculateRandomPoint(ownerPlayer.entityId, num, base.OwnerQuest.ID);
if (!GameManager.Instance.World.CheckForLevelNearbyHeights((float)vector3i.x, (float)vector3i.z, 5) || GameManager.Instance.World.GetWaterAt((float)vector3i.x, (float)vector3i.z))
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition 4a");
return Vector3.zero;
}
World world = GameManager.Instance.World;
Vector3 vector3 = new Vector3((float)vector3i.x, (float)vector3i.y, (float)vector3i.z);
//Log.Out("ObjectiveGotoRandomSDX-GetPosition vector3i.y: " + vector3i.y);
//Log.Out("ObjectiveGotoRandomSDX-GetPosition IsPositionInBounds: " + world.IsPositionInBounds(vector3));
//Log.Out("ObjectiveGotoRandomSDX-GetPosition IsPositionWithinPOI: " + world.IsPositionWithinPOI(vector3, 5));
if (vector3i.y > 0 && world.IsPositionInBounds(vector3) && !world.IsPositionWithinPOI(vector3, 5))
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition 4b");
this.FinalizePoint(vector3i.x, vector3i.y, vector3i.z);
return this.position;
}
}
else
{
//Log.Out("ObjectiveGotoRandomSDX-GetPosition 5");
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageQuestPointTreasureSDX>().Setup(ownerPlayer.entityId, num, 1, base.OwnerQuest.QuestCode, 0, -1, 0, false), false);
base.CurrentValue = 1;
}
//Log.Out("ObjectiveGotoRandomSDX-GetPosition END");
return Vector3.zero;
}
public static Vector3i CalculateRandomPoint(int entityID, float distance, string questID)
{
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint START");
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint distance: " + distance);
World world = GameManager.Instance.World;
EntityAlive entityAlive = world.GetEntity(entityID) as EntityAlive;
var vector = new Vector3(world.GetGameRandom().RandomFloat * 2f + -1f, 0f, world.GetGameRandom().RandomFloat * 2f + -1f);
vector.Normalize();
Vector3 vector2 = entityAlive.position + vector * distance;
int x = (int)vector2.x;
int z = (int)vector2.z;
int y = (int)world.GetHeightAt(vector2.x, vector2.z);
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint x: " + x);
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint y: " + y);
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint z: " + z);
Vector3i vector3i = new Vector3i(x, y, z);
Vector3 vector3 = new Vector3((float)vector3i.x, (float)vector3i.y, (float)vector3i.z);
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint IsPositionInBounds: " + world.IsPositionInBounds(vector3));
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint CanPlaceBlockAt: " + world.CanPlaceBlockAt(vector3i, GameManager.Instance.GetPersistentLocalPlayer(), false));
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint IsPositionWithinPOI: " + world.IsPositionWithinPOI(vector3, 2));
if (!world.IsPositionInBounds(vector3) || (entityAlive is EntityPlayer && !world.CanPlaceBlockAt(vector3i, GameManager.Instance.GetPersistentLocalPlayer(), false)) || world.IsPositionWithinPOI(vector3, 2))
{
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint 1");
return new Vector3i(0, -99999, 0);
}
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint CheckForLevelNearbyHeights: " + world.CheckForLevelNearbyHeights(vector2.x, vector2.z, 5));
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint GetWaterAt: " + world.GetWaterAt(vector2.x, vector2.z));
if (!world.CheckForLevelNearbyHeights(vector2.x, vector2.z, 5) || world.GetWaterAt(vector2.x, vector2.z))
{
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint 2");
return new Vector3i(0, -99999, 0);
}
//Log.Out("ObjectiveGotoRandomSDX-CalculateRandomPoint END");
return vector3i;
}
public void FinalizePoint(int x, int y, int z)
{
//Log.Out("ObjectiveGotoRandomSDX-FinalizePoint START");
this.position = new Vector3((float)x, (float)y, (float)z);
base.OwnerQuest.SetPositionData(Quest.PositionDataTypes.Location, this.position);
base.OwnerQuest.Position = this.position;
this.positionSet = true;
base.OwnerQuest.HandleMapObject(Quest.PositionDataTypes.Location, this.NavObjectName, -1);
base.CurrentValue = 2;
}
public override void Update(float deltaTime)
{
if (Time.time > this.updateTime)
{
this.updateTime = Time.time + 1f;
if (!this.positionSet && base.CurrentValue != 1)
{
//Log.Out("ObjectiveGotoRandomSDX-Update 1");
bool position = this.GetPosition() != Vector3.zero;
}
switch (base.CurrentValue)
{
case 0:
//Log.Out("ObjectiveGotoRandomSDX-Update 2");
bool flag = this.GetPosition() != Vector3.zero;
return;
case 1:
//Log.Out("ObjectiveGotoRandomSDX-Update 3");
break;
case 2:
{
//Log.Out("ObjectiveGotoRandomSDX-Update 4");
Entity ownerPlayer = base.OwnerQuest.OwnerJournal.OwnerPlayer;
if (base.OwnerQuest.NavObject != null && base.OwnerQuest.NavObject.TrackedPosition != this.position)
{
//Log.Out("ObjectiveGotoRandomSDX-Update 5");
base.OwnerQuest.NavObject.TrackedPosition = this.position;
}
Vector3 vector = ownerPlayer.position;
this.distance = Vector3.Distance(vector, this.position);
if (this.distance < this.completionDistance && base.OwnerQuest.CheckRequirements())
{
//Log.Out("ObjectiveGotoRandomSDX-Update 6");
base.CurrentValue = 3;
this.Refresh();
return;
}
break;
}
case 3:
{
//Log.Out("ObjectiveGotoRandomSDX-Update 7");
if (this.completeWithinRange)
{
//Log.Out("ObjectiveGotoRandomSDX-Update 8");
QuestEventManager.Current.RemoveObjectiveToBeUpdated(this);
return;
}
Entity ownerPlayer2 = base.OwnerQuest.OwnerJournal.OwnerPlayer;
if (base.OwnerQuest.NavObject != null && base.OwnerQuest.NavObject.TrackedPosition != this.position)
{
//Log.Out("ObjectiveGotoRandomSDX-Update 9");
base.OwnerQuest.NavObject.TrackedPosition = this.position;
}
Vector3 vector2 = ownerPlayer2.position;
this.distance = Vector3.Distance(vector2, this.position);
if (this.distance > this.completionDistance)
{
//Log.Out("ObjectiveGotoRandomSDX-Update 10");
base.CurrentValue = 2;
this.Refresh();
}
break;
}
default:
//Log.Out("ObjectiveGotoRandomSDX-Update 11");
return;
}
}
}
public override void Refresh()
{
bool complete = base.CurrentValue == 3;
base.Complete = complete;
if (base.Complete)
{
base.OwnerQuest.RefreshQuestCompletion(QuestClass.CompletionTypes.AutoComplete, null, this.PlayObjectiveComplete);
}
}
public override BaseObjective Clone()
{
ObjectiveGotoRandomSDX objectiveRandomGoto = new ObjectiveGotoRandomSDX();
this.CopyValues(objectiveRandomGoto);
objectiveRandomGoto.position = this.position;
objectiveRandomGoto.positionSet = this.positionSet;
objectiveRandomGoto.completionDistance = this.completionDistance;
return objectiveRandomGoto;
}
public override bool SetLocation(Vector3 pos, Vector3 size)
{
this.FinalizePoint((int)pos.x, (int)pos.y, (int)pos.z);
return true;
}
public override void ParseProperties(DynamicProperties properties)
{
base.ParseProperties(properties);
if (properties.Values.ContainsKey(ObjectiveGotoRandomSDX.PropDistance))
{
base.Value = properties.Values[ObjectiveGotoRandomSDX.PropDistance];
}
if (properties.Values.ContainsKey(ObjectiveGotoRandomSDX.PropCompletionDistance))
{
this.completionDistance = StringParsers.ParseFloat(properties.Values[ObjectiveGotoRandomSDX.PropCompletionDistance], 0, -1, NumberStyles.Any);
}
}
protected bool positionSet;
protected float distance;
protected float completionDistance = 10f;
protected Vector3 position;
protected string icon = "ui_game_symbol_quest";
private float updateTime;
protected bool completeWithinRange = true;
public static string PropDistance = "distance";
public static string PropCompletionDistance = "completion_distance";
protected enum GotoStates
{
NoPosition,
WaitingForPoint,
TryComplete,
Completed
}
}