Example #1
0
 public override void Awake()
 {
     Item = gameObject.GetComponent <WorldItem>();
     base.Awake();
     FunctionTarget        = gameObject;
     FunctionName          = "OnPlayerUseWorldItem";
     SecondaryFunctionName = "OnPlayerUseWorldItemSecondary";
     RequirePlayerFocus    = true;
     RequirePlayerTrigger  = false;
     RequireManualEnable   = true;
     ShowDoppleganger      = true;
 }
Example #2
0
 public void RefreshDisplayNames()
 {
     for (int i = 0; i < GenericWorldItems.Count; i++)
     {
         if (string.IsNullOrEmpty(GenericWorldItems [i].DisplayName))
         {
             WorldItem prefab = null;
             if (WorldItems.Get.PackPrefab(GenericWorldItems [i].PackName, GenericWorldItems [i].PrefabName, out prefab))
             {
                 GenericWorldItems [i].DisplayName = prefab.DisplayName;
             }
         }
     }
 }
Example #3
0
        public void OnTriggerExit(Collider other)
        {
            WorldItem worlditem = null;

            if (other.gameObject.HasComponent <WorldItem>(out worlditem))
            {
                mRecentWorldItems.Remove(worlditem);
            }
            BodyPart bodyPart = null;

            if (other.gameObject.HasComponent <BodyPart>(out bodyPart))
            {
                mRecentWorldItems.Remove(bodyPart.Owner.worlditem);
            }
        }
Example #4
0
        public GenericWorldItem(WorldItem item)
        {
            if (item == null)
            {
                Clear();
                return;
            }

            PackName    = item.Props.Name.PackName;
            PrefabName  = item.Props.Name.PrefabName;
            StackName   = item.Props.Name.StackName;
            DisplayName = item.Props.Name.DisplayName;
            Subcategory = item.Props.Local.Subcategory;
            State       = item.State;
        }
Example #5
0
        public void OnPlayerUseWorldItemSecondary(object secondaryResult)
        {
            OptionsListDialogResult dialogResult = secondaryResult as OptionsListDialogResult;

            if (dialogResult.SecondaryResult.Contains("Drink"))
            {
                WorldItem worlditem = null;
                if (WorldItems.Get.PackPrefab(mGenericLiquid.PackName, mGenericLiquid.PrefabName, out worlditem))
                {
                    FoodStuff foodStuff = null;
                    if (worlditem.gameObject.HasComponent <FoodStuff>(out foodStuff))
                    {
                        FoodStuff.Drink(foodStuff);
                    }
                }
            }
            else
            {
                LiquidContainer liquidContainer = null;
                if (Player.Local.Tool.IsEquipped && Player.Local.Tool.worlditem.Is <LiquidContainer>(out liquidContainer))
                {
                    LiquidContainerState liquidContainerState = liquidContainer.State;
                    int    numFilled    = 0;
                    string errorMessage = string.Empty;
                    if (liquidContainerState.TryToFillWith(mGenericLiquid, Int32.MaxValue, out numFilled, out errorMessage))
                    {
                        GUIManager.PostInfo("Filled " + liquidContainer.worlditem.DisplayName + " with " + numFilled.ToString() + " " + mGenericLiquid.PrefabName + "(s)");
                        MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
                    }
                }
//				IWIBase qsItem = null;
//				if (mOptionsListItems.TryGetValue (dialogResult.SecondaryResult, out qsItem)) {
//					System.Object liquidContainerStateObject = null;
//					if (qsItem.GetStateOf <LiquidContainer> (out liquidContainerStateObject)) {
//						LiquidContainerState liquidContainerState = liquidContainerStateObject as LiquidContainerState;
//						if (liquidContainerState != null) {
//							int numFilled = 0;
//							string errorMessage = string.Empty;
//							if (liquidContainerState.TryToFillWith (mGenericLiquid, Int32.MaxValue, out numFilled, out errorMessage)) {
//								GUIManager.PostInfo ("Filled " + qsItem.DisplayName + " with " + numFilled.ToString () + " " + mGenericLiquid.PrefabName + "(s)");
//								MasterAudio.PlaySound (MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
//							}
//						}
//					}
//				}
            }
            mOptionsListItems.Clear();
        }
Example #6
0
        public bool TryToReserve(WorldItem newReservant)
        {
            if (IsReserved && newReservant != mReservant)
            {
                return(false);
            }

            if (CanOccupy(newReservant))
            {
                mReservant         = newReservant;
                mReservationExpire = WorldClock.AdjustedRealTime + WorldClock.RTSecondsToGameSeconds(10.0f);
                return(true);
            }

            return(false);
        }
Example #7
0
        public void CopyFrom(WorldItem worldItem)
        {
            if (worldItem == null)
            {
                Clear();
                return;
            }

            PackName    = worldItem.PackName;
            PrefabName  = worldItem.PrefabName;
            StackName   = worldItem.StackName;
            State       = worldItem.State;
            Subcategory = worldItem.Subcategory;
            DisplayName = worldItem.DisplayName;
            TOD         = WorldClock.TimeOfDayCurrent;
            TOY         = WorldClock.TimeOfYearCurrent;
        }
Example #8
0
        public bool WaitForStructure( )
        {
            if (TargetStructure == null)
            {
                WorldItem childItem = null;
                if (WIGroups.FindChildItem(TargetStructureReference.GroupPath, TargetStructureReference.FileName, out childItem))
                {
                    TargetStructure = childItem.Get <Structure> ();
                    if (TargetStructure != null)
                    {
                        TargetStructure.worlditem.ActiveState = WIActiveState.Active;
                        //TODO remove this lock, could be dangerous
                        TargetStructure.worlditem.ActiveStateLocked = true;
                        Structures.AddInteriorToLoad(TargetStructure);
                    }
                    else
                    {
                        Debug.LogError("Target structure " + TargetStructureReference.FullPath + " had no structure wiscript");
                        return(true);
                    }
                }
                else
                {
                    Debug.LogError("Couldn't find structure " + TargetStructureReference.FullPath);
                    return(true);
                }
            }

            if (TargetStructure.Is(TargetLoadState))
            {
                if (mPaddedStartTime < 0)
                {
                    mPaddedStartTime = WorldClock.AdjustedRealTime + 1.5;
                    return(true);
                }
                else if (WorldClock.AdjustedRealTime > mPaddedStartTime)
                {
                    return(false);
                }
            }
            else
            {
                mPaddedStartTime = -1;
            }
            return(true);
        }
Example #9
0
        //custom doppleganger script for plants
        public override GameObject GetDoppleganger(WorldItem item, Transform dopplegangerParent, string dopplegangerName, WIMode mode, string state, string subcat, float scaleMultiplier, TimeOfDay tod, TimeOfYear toy)
        {
            GameObject doppleganger = dopplegangerParent.gameObject.FindOrCreateChild(dopplegangerName).gameObject;
            Vector3    offset       = Vector3.zero;

            //we have a lookup based on season so this has to be in season form
            toy = WorldClock.TimeOfYearToSeason(toy);
            Plants.Get.InitializeWorldPlantGameObject(doppleganger, subcat, toy);
            if (Flags.Check((uint)mode, (uint)(WIMode.Stacked | WIMode.Selected | WIMode.Crafting | WIMode.Wear), Flags.CheckType.MatchAny))
            {
                WorldItems.AutoScaleDoppleganger(dopplegangerParent, doppleganger, item.BaseObjectBounds, ref scaleMultiplier, ref offset);
            }
            //TODO debug so this isn't necessary...
            offset.y = 0f;
            WorldItems.ApplyDopplegangerMode(item, doppleganger, mode, scaleMultiplier, offset);
            return(doppleganger);
        }
Example #10
0
        public static bool SpawnCreature(CreatureDen den, WIGroup group, Vector3 spawnPosition, bool isDead, string causeOfDeath, float timeSinceDeath, out Creature newCreature)
        {
            if (Globals.MissionDevelopmentMode)
            {
                //we don't care about creatures in mission dev mode
                newCreature = null;
                return(false);
            }

            newCreature = null;
            CreatureTemplate template = null;

            if (mTemplateLookup.TryGetValue(den.State.NameOfCreature.ToLower().Trim(), out template))
            {
                WorldItem newCreatureWorldItem = null;
                if (WorldItems.CloneFromPrefab(Get.CreatureBase.GetComponent <WorldItem> (), group, out newCreatureWorldItem))
                {
                    //since this is the first time the creature is spawned
                    //it has no idea what it is
                    //so before we send it back we're going to set its template name
                    newCreature = newCreatureWorldItem.gameObject.GetOrAdd <Creature> ();
                    newCreature.State.TemplateName = template.Name;
                    newCreature.Template           = template;
                    if (isDead)
                    {
                        Debug.Log("Spawning dead creature");
                        newCreature.State.IsDead = true;
                        Damageable damageable = newCreature.GetComponent <Damageable> ();
                        damageable.State.CauseOfDeath = causeOfDeath;
                        damageable.State.DamageTaken  = damageable.State.Durability;
                        damageable.State.TimeKilled   = WorldClock.AdjustedRealTime - timeSinceDeath;
                    }
                    else
                    {
                        newCreature.State.IsDead = false;
                    }
                    newCreature.Den = den;
                    newCreatureWorldItem.Props.Local.Transform.Position   = spawnPosition;
                    newCreatureWorldItem.Props.Local.Transform.Rotation.y = UnityEngine.Random.Range(0f, 360f);
                    //Debug.Log ("Setting position of creature to " + spawnPosition.ToString ());
                }
            }
            //and that's it! the rest will be taken care of by the creature
            return(newCreature != null);
        }
Example #11
0
        protected IEnumerator PostIntrospectionOverTime()
        {
            //wait for cutscenes / loading / etc. to finsih
            while (!GameManager.Is(FGameState.InGame) || !Player.Local.HasSpawned)
            {
                double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 0.1f;
                while (Frontiers.WorldClock.AdjustedRealTime < waitUntil)
                {
                    yield return(null);
                }
            }

            yield return(null);

            for (int i = 0; i < State.IntrospectionMessages.Count; i++)                                         //if this is the last one, trigger the mission (if any)
            {
                if (i == State.IntrospectionMessages.Count - 1)
                {
                    if (State.ActivateMission)
                    {
                        GUI.GUIManager.PostIntrospection(State.IntrospectionMessages[i], State.ActivatedMissionName, State.Delay);
                    }
                    else
                    {
                        GUI.GUIManager.PostIntrospection(State.IntrospectionMessages[i], State.Delay);
                    }
                }
                else
                {
                    GUI.GUIManager.PostIntrospection(State.IntrospectionMessages[i], State.Delay);
                }
            }

            if (State.PayAttentionToItem)
            {
                WorldItem attentionItem = null;
                if (WIGroups.FindChildItem(State.AttentionItem.GroupPath, State.AttentionItem.FileName, out attentionItem))
                {
                    Player.Local.Focus.GetOrReleaseAttention(attentionItem);
                }
            }
            mPostingIntrospectionOverTime = false;
            yield break;
        }
Example #12
0
        public WITemplate(WorldItem worlditem)
        {
            Name = worlditem.Props.Name.PrefabName;
            StackItem si = worlditem.GetTemplate();

            Props.CopyLocalNames(si.Props);
            Props.CopyGlobalNames(si.Props);
            Props.CopyLocal(si.Props);
            Props.Global             = worlditem.Props.Global;
            SaveState                = si.SaveState;
            Props.Local.Mode         = WIMode.Unloaded;
            Props.Local.PreviousMode = WIMode.Unloaded;
            WIStates states = null;

            if (worlditem.gameObject.HasComponent <WIStates>(out states))
            {
                ObjectStates.AddRange(states.States);
            }
        }
        public override bool OnPlayerEnter()
        {
            if (mDimmingLanterns)
            {
                return(false);
            }

            if (LanternsToDim.Count == 0)
            {
                WorldItem lanternWorldItem = null;
                for (int i = 0; i < State.LanternsToDim.Count; i++)
                {
                    MobileReference mr = State.LanternsToDim[i];
                    if (WIGroups.FindChildItem(mr.GroupPath, mr.FileName, out lanternWorldItem))
                    {
                        LanternsToDim.Add(lanternWorldItem);
                    }
                }
                if (State.LanternsToDim.Count == 0)
                {
                    return(false);
                }
            }

            if (GuardInterventionTrigger == null)
            {
                WorldTriggerState wts = null;
                if (ParentChunk.GetTriggerState(State.GuardInterventionTriggerName, out wts))
                {
                    GuardInterventionTrigger = wts.trigger as TriggerGuardIntervention;
                }
                else
                {
                    return(false);
                }
            }

            mDimmingLanterns = true;
            mStartTime       = WorldClock.AdjustedRealTime;
            StartCoroutine(DimLanternsOverTime());

            return(true);
        }
Example #14
0
        public void SendToStateList(WorldItem w)
        {
            if (w == null || w.Is(WILoadState.Unloading | WILoadState.Unloaded))
            {
                return;
            }

            if (w.ActiveStateLocked)
            {
                LockedWorldItems.Add(w);
                ActiveWorldItems.Remove(w);
                VisibleWorldItems.Remove(w);
                InvisibleWorldItems.Remove(w);
            }
            else
            {
                switch (w.ActiveState)
                {
                case WIActiveState.Invisible:
                default:
                    LockedWorldItems.Remove(w);
                    ActiveWorldItems.Remove(w);
                    VisibleWorldItems.Remove(w);
                    InvisibleWorldItems.Add(w);
                    break;

                case WIActiveState.Visible:
                    LockedWorldItems.Remove(w);
                    ActiveWorldItems.Remove(w);
                    VisibleWorldItems.Add(w);
                    InvisibleWorldItems.Remove(w);
                    break;

                case WIActiveState.Active:
                    LockedWorldItems.Remove(w);
                    ActiveWorldItems.Add(w);
                    VisibleWorldItems.Remove(w);
                    InvisibleWorldItems.Remove(w);
                    break;
                }
            }
        }
Example #15
0
        public void HandleTriggerFinish(Collider other)
        {
            bool quit = false;

            switch (mBaseState.Behavior)
            {
            case AvailabilityBehavior.Once:
                if (mBaseState.NumTimesTriggered > 0)
                {
                    quit = true;
                }
                break;

            case AvailabilityBehavior.Max:
                if (mBaseState.NumTimesTriggered >= mBaseState.MaxTimesTriggered)
                {
                    quit = true;
                }
                break;

            default:
                break;
            }

            if (quit)
            {
                return;
            }

            WorldItem worlditem = null;

            if (other.gameObject.HasComponent <WorldItem>(out worlditem))
            {
                mRecentWorldItems.Remove(worlditem);
            }
            BodyPart bodyPart = null;

            if (other.gameObject.HasComponent <BodyPart>(out bodyPart))
            {
                mRecentWorldItems.Remove(bodyPart.Owner.worlditem);
            }
        }
Example #16
0
        public void OnLocationLoaded(WorldItem locationWorldItem)
        {
            LocationsLeft--;
            //int positionInSpline = -1;
            KeyValuePair <int, MobileReference> reference;

            if (LocationsToLookup.TryGetValue(locationWorldItem.FileName, out reference))
            {
                Location location = null;
                if (locationWorldItem.Is <Location>(out location))
                {
                    ////Debug.Log ("LOCATION " + locationWorldItem.FileName + " HAD A PLACE IN THE PATH " + BrokenPath.SafeName);
                    BrokenPath.spline.splineNodesArray[reference.Key] = location.Node;
                }
            }
            else
            {
                ////Debug.Log ("LOCATION " + locationWorldItem.FileName + " HAS NO PLACE IN SPLINE FOR PATH " + BrokenPath.SafeName);
            }
        }
Example #17
0
        public void SetTransformVisibility(Transform tr, Vector3 cameraPos)
        {
            WorldItem wi = tr.GetComponent <WorldItem>();

            if (wi != null)
            {
                if (Vector3.Distance(cameraPos, wi.Position) < wi.VisibleDistance)
                {
                    wi.gameObject.SetActive(true);
                }
                else
                {
                    wi.gameObject.SetActive(false);
                }
            }
            foreach (Transform c in tr)
            {
                SetTransformVisibility(c, cameraPos);
            }
        }
Example #18
0
        // = new GenericWorldItem ();
        public void CreateDarkrotSpawner(Vector3 spawnerPosition, Vector3 spawnerRotation, WIGroup group, int numDarkrotReleaesd, float releaseDelay, float releaseInterval)
        {
            StackItem spawnerStackItem = gDarkrotSpawner.ToStackItem();

            spawnerStackItem.Transform.Position          = spawnerPosition;
            spawnerStackItem.Transform.Rotation          = spawnerRotation;
            spawnerStackItem.Props.Local.FreezeOnStartup = true;
            spawnerStackItem.Props.Local.Mode            = WIMode.Frozen;
            WorldItem newSpawner = null;

            if (WorldItems.CloneFromStackItem(spawnerStackItem, group, out newSpawner))
            {
                newSpawner.Initialize();
                DarkrotSpawner ds = newSpawner.Get <DarkrotSpawner> ();
                ds.State.MaxDarkrotAtOneTime = numDarkrotReleaesd;
                ds.State.SpawnDelay          = releaseDelay;
                ds.State.SpawnInterval       = releaseInterval;
            }
            Debug.Log("Created spawner");
        }
Example #19
0
        public override GameObject GetDoppleganger(WorldItem item, Transform dopplegangerParent, string dopplegangerName, WIMode mode, string state, string subcat, float scaleMultiplier, TimeOfDay tod, TimeOfYear toy)
        {
            GameObject doppleganger = dopplegangerParent.gameObject.FindOrCreateChild(dopplegangerName).gameObject;
            //use the subcat to get our blueprint result
            Vector3 offset = Vector3.zero;

            ItemBounds.size               = Vector3.one;
            ItemBounds.center             = Vector3.zero;
            doppleganger.transform.parent = null;
            doppleganger.transform.ResetLocal();
            PreparedFoods.InitializePreparedFoodGameObject(doppleganger, subcat, true, ref ItemBounds);
            doppleganger.transform.parent = dopplegangerParent;
            if (Flags.Check((uint)mode, (uint)(WIMode.Stacked | WIMode.Selected | WIMode.Crafting | WIMode.Wear), Flags.CheckType.MatchAny))
            {
                WorldItems.AutoScaleDoppleganger(dopplegangerParent, doppleganger, ItemBounds, ref scaleMultiplier, ref offset);
            }
            WorldItems.ApplyDopplegangerMode(item, doppleganger, mode, scaleMultiplier, offset);
            WorldItems.ApplyDopplegangerMaterials(doppleganger, mode);
            return(doppleganger);
        }
Example #20
0
        public void EditorCreateStates()
        {
            WorldItem worlditem = gameObject.GetComponent <WorldItem> ();

            worlditem.Colliders.Clear();
            worlditem.Renderers.Clear();
            worlditem.Props.Global.ParentColliderType = WIColliderType.None;

            States.Clear();
            foreach (Transform child in transform)
            {
                child.gameObject.tag = "StateChild";
                WIState newState = new WIState();
                newState.Name   = child.name;
                newState.Suffix = child.name;
                BoxCollider bc = child.gameObject.GetOrAdd <BoxCollider> ();
                bc.enabled = false;

                switch (newState.Name)
                {
                case "Rotten":
                case "Burned":
                case "Preserved":
                    newState.IsPermanent = true;
                    child.gameObject.SetActive(false);
                    break;

                case "Raw":
                    child.gameObject.SetActive(true);
                    break;

                default:
                    child.gameObject.SetActive(false);
                    break;
                }

                States.Add(newState);
            }
        }
Example #21
0
        public bool CanOccupy(WorldItem newOccupant)
        {
            bool canOccupy = false;

            if (HasOccupant && mOccupant == newOccupant)
            {
                return(true);
            }

            switch (State.Users)
            {
            case ActionNodeUsers.AnyOccupant:
                //ANY occupant you say? we'll see about that...
                switch (State.Type)
                {
                case ActionNodeType.QuestNode:
                case ActionNodeType.DailyRoutine:
                    //we can only occupy if someone else isn't already occupying
                    //this is because characters have to be able to finish their routines
                    //without getting interrupted
                    canOccupy = !HasOccupant;
                    break;

                case ActionNodeType.Generic:
                default:
                    //we can occupy even if it means displacing another occupant
                    canOccupy = true;
                    break;
                }
                break;

            case ActionNodeUsers.SpecifiedOccupantOnly:
                //if it's specified occupant only we have to match the file name
                canOccupy = (newOccupant.FileName == State.OccupantName);
                break;
            }
            return(canOccupy);
        }
Example #22
0
        public virtual bool TakeDamage(WIMaterialType materialType, Vector3 damagePoint, float attemptedDamage, Vector3 attemptedForce, string damageSource, out float actualDamage, out bool isDead)
        {
            actualDamage = attemptedDamage;
            isDead       = false;
            TotalDamage += actualDamage;

            if (!mRustling)
            {
                StartCoroutine(RustleOverTime(null));
            }

            if (HasPlayerFocus)
            {
                GUIHud.Get.ShowProgressBar(Colors.Get.GeneralHighlightColor, Colors.Darken(Colors.Get.GenericNeutralValue), NormalizedDamage);
            }

            if (SpawnOnDamaage && TotalDamage >= SpawnDamageMinimum)                                            //reset
            {
                TotalDamage = 0f;
                //spawn a thing
                WorldItem worlditem = null;
                if (WorldItems.CloneRandomFromCategory(SpawnCategory, ParentChunk.AboveGroundGroup, out worlditem))
                {
                    //spit it out at the player
                    Vector3 direction = (Player.Local.Position - damagePoint).normalized * 5f;
                    worlditem.tr.parent   = ParentChunk.AboveGroundGroup.transform;
                    worlditem.tr.position = damagePoint;
                    worlditem.Props.Local.FreezeOnStartup = false;
                    worlditem.Props.Local.Transform.CopyFrom(worlditem.tr);
                    worlditem.Initialize();
                    worlditem.SetMode(WIMode.World);
                    worlditem.ApplyForce(direction, damagePoint);
                }
            }
            return(true);
        }
Example #23
0
        public void OnPlayerUseWorldItemSecondary(object secondaryResult)
        {
            OptionsListDialogResult dialogResult = secondaryResult as OptionsListDialogResult;

            switch (dialogResult.SecondaryResult)
            {
            case "PourOnSelf":
                MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
                Player.Local.Status.RemoveCondition("BurnedByFire");
                Player.Local.Status.AddCondition("Wet");
                State.Contents.Clear();
                break;

            case "Drink":
                WorldItem liquid = null;
                if (WorldItems.Get.PackPrefab(State.Contents.PackName, State.Contents.PrefabName, out liquid))                                                                  //this is tricky - we want to drink it without destroying the prefab
                {
                    FoodStuff foodstuff = null;
                    if (liquid.Is <FoodStuff>(out foodstuff))                                                                                   //DON'T consume the foodstuff!
                    {
                        FoodStuff.Drink(foodstuff);
                        State.Contents.InstanceWeight--;
                        GUIManager.PostInfo("Drank 1 " + State.Contents.PrefabName + ", " + State.Contents.InstanceWeight.ToString() + "/" + State.Capacity.ToString() + " left.");
                    }
                }
                break;

            case "Pour Out":
                //two options here
                //if we're in the inventory then we want to add our contents to the selected stack
                //if we're in the world we want to dump it into the world
                bool playSound = false;
                if (PrimaryInterface.IsMaximized("Inventory"))
                {
                    WIStack selectedStack = Player.Local.Inventory.SelectedStack;
                    if (Stacks.Can.Stack(selectedStack, State.Contents))
                    {
                        WIStackError error = WIStackError.None;
                        for (int i = 0; i < State.Contents.InstanceWeight; i++)
                        {
                            StackItem contents = State.Contents.ToStackItem();
                            if (!Stacks.Push.Item(selectedStack, contents, ref error))
                            {
                                break;
                            }
                            else
                            {
                                playSound = true;
                            }
                        }
                    }
                }
                else
                {
                    State.Contents.Clear();
                    GUIManager.PostInfo("Discarded contents");
                    if (Player.Local.Surroundings.IsWorldItemInRange)
                    {
                        Flammable flammable = null;
                        if (Player.Local.Surroundings.WorldItemFocus.worlditem.Is <Flammable>(out flammable) && flammable.IsOnFire)
                        {
                            flammable.Extinguish();
                        }
                    }
                    playSound = true;
                }
                if (playSound)
                {
                    MasterAudio.PlaySound(MasterAudio.SoundType.PlayerInterface, "FillLiquidContainer");
                }
                break;

            default:
                break;
            }
        }
Example #24
0
        public void OnTriggerEnter(Collider other)
        {
            if (!Application.isPlaying)
            {
                return;
            }

            bool checkWorldItem = false;
            bool checkPlayer    = false;

            switch (other.gameObject.layer)
            {
            case Globals.LayerNumWorldItemActive:
                checkWorldItem = true;
                break;

            case Globals.LayerNumPlayer:
                checkPlayer = true;
                break;

            default:
                break;
            }

            if (!checkWorldItem || checkPlayer)                                      //get out before we do anything
            {
                return;
            }

            //okay so we've got a world item layer, now see if we actually have a world item
            WorldItem worlditem = null;

            if (checkWorldItem)                                                //see if the actual object is a world item
            {
                if (!other.gameObject.HasComponent <WorldItem>(out worlditem)) //if the object isn't a worlditem then maybe it's a body part
                {
                    BodyPart bodyPart = null;
                    if (other.gameObject.HasComponent <BodyPart>(out bodyPart))                                                              //store the body part's world item for later
                    {
                        worlditem = bodyPart.Owner.worlditem;
                    }
                }
                //did we find one?
                if (worlditem != null)                                                  //if we're still null at this point it's a bust
                {
                    if (!mRecentWorldItems.Add(worlditem))
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            Character character = null;
            Motile    motile    = null;

            if (worlditem.Is <Character>(out character) &&
                worlditem.Is <Motile>(out motile))
            {
                OnCharacterEnter(character, motile);
            }

            if (!mSendingEvents)
            {
                StartCoroutine(SendEvents(ActionNodeBehavior.OnTriggerEnter));
            }
        }
Example #25
0
        protected IEnumerator FindValuablesOverTime()
        {
            //give ourselves a second before looking for a flower
            double waitUntil = WorldClock.AdjustedRealTime + 1f;

            while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed)
            {
                yield return(null);
            }

            while (!mDestroyed)
            {
                while (WorldClock.AdjustedRealTime < StartleTimeEnd)
                {
                    yield return(null);
                }

                while (GameWorld.Get.PrimaryChunk == null || GameWorld.Get.PrimaryChunk.AboveGroundGroup == null)
                {
                    yield return(null);
                }

                if (CurrentValuable == null)
                {
                    List <WorldItem> valuables = new List <WorldItem> ();
                    //find something between the player and the critter, closer if it's friendlier
                    //TODO make this work in immediate groups
                    var searchEnum = WIGroups.GetAllChildrenByTypeInLocation(GameWorld.Get.PrimaryChunk.AboveGroundGroup.Path, ValuableScripts, valuables, Position, SearchRadius, false, 1);
                    while (searchEnum.MoveNext())
                    {
                        yield return(searchEnum.Current);
                    }
                    if (valuables.Count > 0)
                    {
                        valuableIsHeldByPlayer   = false;
                        CurrentValuable          = valuables [0];
                        mCurrentValuablePosition = valuables [0].worlditem.FocusPosition;
                        mRandomValuablePosition  = valuables [0].worlditem.FocusPosition;
                    }
                }

                if (CurrentValuable == null)
                {
                    //find something between the player and the critter, closer if it's friendlier
                    //TODO make this work in immediate groups
                    List <WorldItem> valuables = WIGroups.Get.Player.GetChildrenOfType(ValuableScripts);
                    if (valuables.Count > 0)
                    {
                        valuableIsHeldByPlayer   = true;
                        CurrentValuable          = valuables [0];
                        mCurrentValuablePosition = valuables [0].worlditem.FocusPosition;
                        mRandomValuablePosition  = valuables [0].worlditem.FocusPosition;
                    }
                }

                waitUntil = WorldClock.AdjustedRealTime + 1.5f;
                while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed)
                {
                    yield return(null);
                }
                yield return(null);
            }
        }
Example #26
0
 public void Awake()
 {
     worlditem = gameObject.GetComponent <WorldItem>();
 }
Example #27
0
 public virtual void Awake( )
 {
     Item = gameObject.GetComponent <WorldItem> ( );
 }
Example #28
0
        //this function causes tons of lag
        //there are better ways to do this stuff i just need to update it
        public void HandleTriggerStart(Collider other)
        {
            //TODO use WorldItems.GetIOIFromCollider
            //replace all this other crap

            bool quit = false;

            switch (mBaseState.Behavior)
            {
            case AvailabilityBehavior.Once:
                if (mBaseState.NumTimesTriggered > 0)
                {
                    quit = true;
                }
                break;

            case AvailabilityBehavior.Max:
                if (mBaseState.NumTimesTriggered >= mBaseState.MaxTimesTriggered)
                {
                    quit = true;
                }
                break;

            default:
                break;
            }

            if (quit)
            {
                return;
            }

            bool checkWorldItem = false;
            bool checkPlayer    = false;

            switch (other.gameObject.layer)
            {
            case Globals.LayerNumWorldItemActive:
                checkWorldItem = true;
                break;

            case Globals.LayerNumPlayer:
                checkPlayer = true;
                break;

            default:
                break;
            }

            if (!(checkWorldItem || checkPlayer))   //get out before we do anything
            {
                return;
            }

            //okay so we've got a world item layer, now see if we actually have a world item
            WorldItem worlditem = null;

            if (checkWorldItem)                                                //see if the actual object is a world item
            {
                if (!other.gameObject.HasComponent <WorldItem>(out worlditem)) //if the object isn't a worlditem then maybe it's a body part
                {
                    BodyPart bodyPart = null;
                    if (other.gameObject.HasComponent <BodyPart>(out bodyPart)) //store the body part's world item for later
                    {
                        worlditem = bodyPart.Owner.worlditem;
                    }
                }
                //did we find one?
                if (worlditem != null)  //if we're still null at this point it's a bust
                {
                    if (!mRecentWorldItems.Add(worlditem))
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            //okay, next check if we're actually a target
            bool meetsTargetRequirements   = true;
            WorldTriggerTarget finalTarget = WorldTriggerTarget.None;

            mCharacter = null;
            mQuestItem = null;
            if (checkPlayer)
            {
                finalTarget = WorldTriggerTarget.Player;
                if (!Flags.Check((uint)mBaseState.Targets, (uint)WorldTriggerTarget.Player, Flags.CheckType.MatchAny))
                {
                    meetsTargetRequirements = false;
                }
            }
            else if (checkWorldItem)                                                                                     //worlditems can be characters creatures and all
            {
                if (Flags.Check((uint)mBaseState.Targets, (uint)WorldTriggerTarget.WorldItem, Flags.CheckType.MatchAny)) //it's just true outright no matter what else it is
                {
                    meetsTargetRequirements = true;
                    finalTarget             = WorldTriggerTarget.WorldItem;
                }
                else    //otherwise check for quest item, character and creature scripts
                        //the heirarchy is WorldItem->Character->Creature->QuestItem
                {
                    if (Flags.Check((uint)mBaseState.Targets, (uint)WorldTriggerTarget.Character, Flags.CheckType.MatchAny))
                    {
                        meetsTargetRequirements = worlditem.Has <Character>(out mCharacter);
                        finalTarget             = WorldTriggerTarget.Character;
                    }
                    else if (Flags.Check((uint)mBaseState.Targets, (uint)WorldTriggerTarget.QuestItem, Flags.CheckType.MatchAny))
                    {
                        meetsTargetRequirements = worlditem.Has <QuestItem>(out mQuestItem);
                        finalTarget             = WorldTriggerTarget.QuestItem;
                    }
                }
            }
            //if we made it this far without meeting requirements we're done
            if (!meetsTargetRequirements)   //get out now
            {
                return;
            }

            if (!WorldClock.Is(mBaseState.TimeOfDayRequirement))
            {
                return;
            }

            if (!string.IsNullOrEmpty(mBaseState.QuestItemRequirement) && !Player.Local.Inventory.HasQuestItem(mBaseState.QuestItemRequirement))
            {
                return;
            }

            //at this point we're ready to waste time checking if we meet mission requirements
            bool          meetsMissionRequirements = true;
            bool          missionCompleted         = false;
            bool          objectiveCompleted       = false;
            MissionStatus missionStatus            = MissionStatus.Dormant;
            MissionStatus objectiveStatus          = MissionStatus.Dormant;

            switch (mBaseState.MissionRequirement)
            {
            case MissionRequireType.None:
            default:
                break;

            case MissionRequireType.RequireActive:
                Missions.Get.MissionStatusByName(mBaseState.MissionName, ref missionStatus);
                meetsMissionRequirements &= Flags.Check((uint)missionStatus, (uint)MissionStatus.Active, Flags.CheckType.MatchAny);
                break;

            case MissionRequireType.RequireActiveAndNotFailed:
                Missions.Get.MissionStatusByName(mBaseState.MissionName, ref missionStatus);
                missionCompleted          = Missions.Get.MissionCompletedByName(mBaseState.MissionName, ref missionCompleted);
                meetsMissionRequirements &= (missionCompleted && !Flags.Check((uint)missionStatus, (uint)MissionStatus.Failed, Flags.CheckType.MatchAny));
                break;

            case MissionRequireType.RequireCompleted:
                Missions.Get.MissionCompletedByName(mBaseState.MissionName, ref missionCompleted);
                meetsMissionRequirements &= missionCompleted;
                break;

            case MissionRequireType.RequireNotCompleted:
                Missions.Get.MissionCompletedByName(mBaseState.MissionName, ref missionCompleted);
                meetsMissionRequirements &= !missionCompleted;
                break;

            case MissionRequireType.RequireDormant:
                Missions.Get.MissionStatusByName(mBaseState.MissionName, ref missionStatus);
                meetsMissionRequirements &= !Flags.Check((uint)missionStatus, (uint)MissionStatus.Active, Flags.CheckType.MatchAny);
                break;
            }
            //then try objective requirements
            switch (mBaseState.ObjectiveRequirement)
            {
            case MissionRequireType.None:
            default:
                break;

            case MissionRequireType.RequireActive:
                Missions.Get.ObjectiveStatusByName(mBaseState.MissionName, mBaseState.ObjectiveName, ref objectiveStatus);
                meetsMissionRequirements &= Flags.Check((uint)objectiveStatus, (uint)MissionStatus.Active, Flags.CheckType.MatchAny);
                break;

            case MissionRequireType.RequireActiveAndNotFailed:
                Missions.Get.ObjectiveStatusByName(mBaseState.MissionName, mBaseState.ObjectiveName, ref objectiveStatus);
                meetsMissionRequirements &= (Flags.Check((uint)objectiveStatus, (uint)MissionStatus.Active, Flags.CheckType.MatchAny) &&
                                             !Flags.Check((uint)objectiveStatus, (uint)MissionStatus.Failed, Flags.CheckType.MatchAny));
                break;

            case MissionRequireType.RequireCompleted:
                Missions.Get.ObjectiveCompletedByName(mBaseState.MissionName, mBaseState.ObjectiveName, ref objectiveCompleted);
                meetsMissionRequirements &= objectiveCompleted;
                break;

            case MissionRequireType.RequireNotCompleted:
                Missions.Get.ObjectiveCompletedByName(mBaseState.MissionName, mBaseState.ObjectiveName, ref objectiveCompleted);
                meetsMissionRequirements &= !objectiveCompleted;
                break;

            case MissionRequireType.RequireDormant:
                Missions.Get.ObjectiveStatusByName(mBaseState.MissionName, mBaseState.ObjectiveName, ref objectiveStatus);
                meetsMissionRequirements &= !Flags.Check((uint)objectiveStatus, (uint)MissionStatus.Active, Flags.CheckType.MatchAny);
                break;
            }
            //if we don't meet those requirements...
            if (!meetsMissionRequirements)  //get out before we start messing with worlditems
            {
                return;
            }

            bool meetsTriggerRequirements = true;

            //finally check if we need to wait on other triggers
            switch (mBaseState.TriggerRequirement)
            {
            case TriggerRequireType.None:
            default:
                break;

            case TriggerRequireType.RequireNotTriggered:

                break;

            case TriggerRequireType.RequireTriggered:
                break;
            }
            if (!meetsTriggerRequirements)
            {
                //oops
                return;
            }

            //well, we've made it this far! we've actually triggered
            //alright, time to call the appropriate function based on the final target type
            bool triggered = false;

            switch (finalTarget)
            {
            case WorldTriggerTarget.Player:
                triggered = OnPlayerEnter();
                break;

            case WorldTriggerTarget.WorldItem:
                triggered = OnWorldItemEnter(worlditem);
                break;

            case WorldTriggerTarget.Character:
                if (!mBaseState.ExcludeCharacters.Contains(mCharacter.worlditem.FileName))
                {
                    triggered = OnCharacterEnter(mCharacter);
                }
                break;

            case WorldTriggerTarget.Creature:
                triggered = true;    //mBaseState.NumTimesTriggered++;
                                     //OnCreatureEnter (creature);
                break;

            case WorldTriggerTarget.QuestItem:
                triggered = OnQuestItemEnter(mQuestItem);
                break;

            case WorldTriggerTarget.None:
            default:
                break;
            }

            if (triggered)
            {
                mBaseState.NumTimesTriggered++;
                ParentChunk.SaveTriggers();
                Player.Get.AvatarActions.ReceiveAction(AvatarAction.TriggerWorldTrigger, WorldClock.AdjustedRealTime);
            }
        }
Example #29
0
 public virtual bool OnWorldItemEnter(WorldItem worlditem)
 {
     return(true);
 }
Example #30
0
        public override void InitializeTemplate()
        {
            WorldItem worlditem = gameObject.GetComponent <WorldItem>();

            worlditem.Props.Local.DisplayNamerScript = "WorldPlant";
        }