//these are both done stupidly and could probably be done through reflection instead but for now... public override Dictionary <string, object> GetExtraData() { Dictionary <string, object> extraData = new Dictionary <string, object>(); var actorData = new ActorExtraData(); //save! actorData.CurrentAiState = CurrentAiState; actorData.LastAiState = LastAiState; actorData.LockAiState = LockAiState; actorData.CurrentAnimState = AnimationComponent.Ref()?.CurrentAnimState ?? default; actorData.LockAnimState = AnimationComponent.Ref()?.LockAnimState ?? default; actorData.SavedTarget = Target != null ? Target.name : string.Empty; //damn it! actorData.AltTarget = MovementComponent.MovementTarget; actorData.TimeInState = TimeInState; actorData.Health = Health; actorData.BeenHit = BeenHit; actorData.IsRunning = MovementComponent.IsRunning; if (InteractionComponent != null) { actorData.InteractionForceDisabled = InteractionComponent.InteractionDisabledByHit; if (InteractionComponent.CorpseContainer != null) { extraData["Container"] = SerializableContainerModel.MakeSerializableContainerModel(InteractionComponent.CorpseContainer); } } extraData["Actor"] = actorData; return(extraData); }
//persistence //should be fixed now public override void SetExtraData(Dictionary <string, object> data) //this either isn't called or doesn't work { if (UseLocalContainer && UsePersistentContainer) { MyContainer = SerializableContainerModel.MakeContainerModel((SerializableContainerModel)data["Container"]); } }
public void Init() { FindComponents(); if (CorpseContainer == null && CorpseItems?.Items != null && CorpseItems.Items.Length > 0) { CorpseContainer = SerializableContainerModel.MakeContainerModel(CorpseItems); } }
public override void RestoreEntityData(Dictionary <string, object> data) { base.RestoreEntityData(data); if (data.ContainsKey("Actor")) { ActorExtraData actorData = data["Actor"] as ActorExtraData; if (actorData != null) { //restore! CurrentAiState = actorData.CurrentAiState; LastAiState = actorData.LastAiState; LockAiState = actorData.LockAiState; if (AnimationComponent != null) { AnimationComponent.CurrentAnimState = actorData.CurrentAnimState; AnimationComponent.LockAnimState = actorData.LockAnimState; } SavedTarget = actorData.SavedTarget; TimeInState = actorData.TimeInState; Health = actorData.Health; BeenHit = actorData.BeenHit; LastHit = actorData.LastHit; LastHitDamage = actorData.LastHitDamage; WasExtremeDeath = actorData.WasExtremeDeath; MovementComponent.BeforeRestore(data); MovementComponent.MovementTarget = actorData.AltTarget; MovementComponent.IsRunning = actorData.IsRunning; if (CurrentAiState == ActorAiState.Dead) { MovementComponent.HandleDeath(); } if (InteractionComponent != null) { InteractionComponent.InteractionDisabledByHit = actorData.InteractionForceDisabled; if (data.ContainsKey("Container")) { InteractionComponent.CorpseContainer = SerializableContainerModel.MakeContainerModel((SerializableContainerModel)data["Container"]); } } } else { CDebug.LogEx(string.Format("Invalid actor data for {0} found on restore!", this.name), LogLevel.Error, this); } } else { CDebug.LogEx(string.Format("No actor data for {0} found on restore!", this.name), LogLevel.Error, this); } }
private void RpgInit() { //Debug.LogWarning(nameof(RpgInit)); //TODO better debugging and logging //load initial player try { InitializePlayer(); } catch (Exception e) { Debug.LogError("Failed to load initial player"); Debug.LogException(e); } //hookup factions try { FactionState = FactionModel.CloneFactionModel(FactionModel.BaseModel); } catch (Exception e) { Debug.LogError("Failed to load faction model"); Debug.LogException(e); } //load initial containers (requires some decoding) //we will actually need to load additional containers ex post facto when we add mod support try { var rawContainers = CoreUtils.LoadJson <Dictionary <string, SerializableContainerModel> >(CoreUtils.LoadResource <TextAsset>("Data/RPGDefs/init_containers").text); foreach (var key in rawContainers.Keys) { var value = rawContainers[key]; try { var realContainer = SerializableContainerModel.MakeContainerModel(value); instance.ContainerState.Add(key, realContainer); } catch (Exception e) { Debug.LogError("Failed to load one container"); Debug.LogException(e); } } } catch (Exception e) { Debug.LogError("Failed to load initial container state"); Debug.LogException(e); } instance.InitialLoaded = true; }
public override Dictionary <string, object> GetExtraData() //this works { var data = new Dictionary <string, object>(); if (UseLocalContainer && UsePersistentContainer) { data.Add("Container", SerializableContainerModel.MakeSerializableContainerModel(MyContainer)); } return(data); }
private void RpgInit() { //Debug.LogWarning(nameof(RpgInit)); //TODO better debugging and logging //load initial player try { instance.PlayerRpgState = new CharacterModel(); JsonConvert.PopulateObject(CoreUtils.LoadResource <TextAsset>("Data/RPGDefs/init_player").text, instance.PlayerRpgState, new JsonSerializerSettings { Converters = CCJsonConverters.Defaults.Converters, TypeNameHandling = TypeNameHandling.Auto, NullValueHandling = NullValueHandling.Ignore }); instance.PlayerRpgState.UpdateStats(); PlayerFlags.RegisterSource(instance.PlayerRpgState); } catch (Exception e) { Debug.LogError("Failed to load initial player"); Debug.LogException(e); } //load initial containers (requires some decoding) //we will actually need to load additional containers ex post facto when we add mod support try { var rawContainers = CoreUtils.LoadJson <Dictionary <string, SerializableContainerModel> >(CoreUtils.LoadResource <TextAsset>("Data/RPGDefs/init_containers").text); foreach (var key in rawContainers.Keys) { var value = rawContainers[key]; try { var realContainer = SerializableContainerModel.MakeContainerModel(value); instance.ContainerState.Add(key, realContainer); } catch (Exception e) { Debug.LogError("Failed to load one container"); Debug.LogException(e); } } } catch (Exception e) { Debug.LogError("Failed to load initial container state"); Debug.LogException(e); } instance.InitialLoaded = true; }
public override void Start() { base.Start(); if (!UseLocalContainer) { MyContainer = GameState.Instance.ContainerState[SharedContainer]; } else if (MyContainer == null) //should fix... { MyContainer = SerializableContainerModel.MakeContainerModel(LocalContainer); //called after and overriding save? } }
public override void Start() { base.Start(); if (!UseLocalContainer) { MyContainer = GameState.Instance.ContainerState[SharedContainer]; } else if (MyContainer == null) //should fix... { MyContainer = SerializableContainerModel.MakeContainerModel(LocalContainer); //called after and overriding save? } TryExecuteOnComponents(component => component.Init(this)); Initialized = true; }
//these are both done stupidly and could probably be done through reflection instead but for now... public override Dictionary <string, object> CommitEntityData() { Dictionary <string, object> extraData = base.CommitEntityData(); var actorData = new ActorExtraData(); //save! actorData.CurrentAiState = CurrentAiState; actorData.LastAiState = LastAiState; actorData.LockAiState = LockAiState; actorData.CurrentAnimState = AnimationComponent.Ref()?.CurrentAnimState ?? default; actorData.LockAnimState = AnimationComponent.Ref()?.LockAnimState ?? default; actorData.SavedTarget = Target != null ? Target.name : string.Empty; //damn it! actorData.AltTarget = MovementComponent.MovementTarget; actorData.TimeInState = TimeInState; actorData.Health = Health; actorData.BeenHit = BeenHit; if (LastHit.HasValue) { var modLastHit = LastHit.Value; modLastHit.Originator = null; //hack because this breaks saves and we don't need it for death handling anyway actorData.LastHit = modLastHit; } actorData.LastHitDamage = LastHitDamage; actorData.WasExtremeDeath = WasExtremeDeath; MovementComponent.BeforeCommit(extraData); actorData.IsRunning = MovementComponent.IsRunning; if (InteractionComponent != null) { actorData.InteractionForceDisabled = InteractionComponent.InteractionDisabledByHit; if (InteractionComponent.CorpseContainer != null) { extraData["Container"] = SerializableContainerModel.MakeSerializableContainerModel(InteractionComponent.CorpseContainer); } } extraData["Actor"] = actorData; return(extraData); }