Example #1
0
        public void Initialize()
        {
            string startupState = DefaultState;

            if (worlditem.HasSaveState && !string.IsNullOrEmpty(worlditem.SaveState.LastState))
            {
                //Debug.Log("Setting startup state to " + worlditem.SaveState.LastState + " in states");
                startupState = worlditem.SaveState.LastState;
            }
            else
            {
                //Debug.Log("Didn't have save state or startup state was empty in states");
            }

            for (int i = 0; i < States.Count; i++)
            {
                if (States [i].CanUseToSelect)
                {
                    worlditem.OnPlayerUse += OnPlayerUse;
                }
            }

            SetState(startupState);
            worlditem.OnModeChange   += OnModeChange;
            worlditem.OnAddedToGroup += OnAddedToGroup;
            Equippable e = null;

            if (worlditem.Is <Equippable> (out e))
            {
                e.OnEquip += OnEquip;
            }
        }
Example #2
0
 public override bool TryToSpawn(bool forceSpawn, out GUIOptionListDialog childEditor, Camera nguiCamera)
 {
     childEditor = null;
     if (IsInUse || Item.Is(WIMode.RemovedFromGame))
     {
         return(false);
     }
     MessageType = Item.DisplayName;
     if (base.TryToSpawn(forceSpawn, out childEditor, nguiCamera))
     {
         if (ShowDoppleganger)
         {
             mChildEditor.DopplegangerProps.CopyFrom(Item);
             mChildEditor.RefreshDoppleganger();
         }
         else
         {
             mChildEditor.DopplegangerProps.Clear();
         }
         return(true);
     }
     return(false);
 }
Example #3
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 #4
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 #5
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 #6
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 #7
0
        public bool TryToOccupyNode(WorldItem newOccupant)
        {
            if (newOccupant == mReservant)
            {
                mOccupant = mReservant;
                return(true);
            }

            if (!CanOccupy(newOccupant) || !HasOccupantReached(newOccupant))                                      //whoops, we either can't use this or we're too far away
            {
                return(false);
            }

            if (HasOccupant && newOccupant != mOccupant)                                      //if we've made it this far and we have an occupant
            //they need to be displaced
            {
                VacateNode(mOccupant);
            }

            //hooray we're the new occupant
            State.NumTimesOccupied++;
            mOccupant = newOccupant;
            if (State.OccupantName == mOccupant.FileName)                                      //if we match the specific occupant for this node
            {
                State.NumTimesOccupiedSpecific++;
            }

            if (!mSendingEvents)
            {
                StartCoroutine(SendEvents(ActionNodeBehavior.OnOccupy));
            }

            //align to action node direction
            //load custom animation
            //if we have a speech, this will be overridden
            Motile motile = null;

            if (mOccupant.Is <Motile>(out motile))
            {
                //if we told the occupant to come here
                MotileAction topAction = motile.TopAction;
                if (topAction.Type == MotileActionType.GoToActionNode &&
                    topAction.LiveTarget == this)                                                       //finish the action
                {
                    topAction.TryToFinish();
                }
            }

            //alrighty time for the speech givin'
            //see if this new occupant is talkative
            Talkative talkative = null;

            if (mOccupant.Is <Talkative>(out talkative))
            {
                Speech speech      = null;
                bool   foundSpeech = false;
                switch (State.Speech)
                {
                case ActionNodeSpeech.None:
                default:
                    //there'll be no speechifying today
                    break;

                case ActionNodeSpeech.RandomAnyone:
                    //use speech flags to pull a random speech for anyone who uses this node
                    //not implemented
                    break;

                case ActionNodeSpeech.CustomAnyone:
                    //use speech flags to pull a specified speech for anyone who uses this node
                    //not implemented
                    break;

                case ActionNodeSpeech.RandomCharOnly:
                    //use speech flags to pull a random speech for the specific character that uses this node
                    //not implemented
                    break;

                case ActionNodeSpeech.CustomCharOnly:
                    //use speech flags to pull a specified speech for the specific character that uses this node
                    foundSpeech = Mods.Get.Runtime.LoadMod <Speech>(ref speech, "Speech", State.CustomSpeech);
                    break;

                case ActionNodeSpeech.SequenceCharOnly:
                    //use the custom speech name to get the next speech in a sequence
                    string speechName          = State.CustomSpeech;
                    int    currentSpeechNumber = 1;
                    bool   keepLooking         = true;
                    //TODO look into putting this in Talkative
                    while (keepLooking)                                                                              //get the next speech
                    {
                        speechName = State.CustomSpeech.Replace("[#]", currentSpeechNumber.ToString());
                        if (Mods.Get.Runtime.LoadMod <Speech>(ref speech, "Speech", speechName))                                                                                          //load the speech and see if it's been given by our character
                        {
                            int numTimesStartedBy = speech.NumTimesStartedBy(mOccupant.FileName);
                            if (numTimesStartedBy <= 0)                                                                                                      //if the speech hasn't been started by this character before, use it
                            {
                                keepLooking = false;
                                foundSpeech = true;
                            }
                            else                                                                                                        //otherwise increment the speech number and keep looking
                            {
                                currentSpeechNumber++;
                            }
                        }
                        else                                                                                            //no more speeches to try, oh well
                        {
                            keepLooking = false;
                        }
                    }
                    break;
                }

                if (foundSpeech)
                {
                    talkative.GiveSpeech(speech, this);
                }
            }
            //if we've gotten this far we're golden
            return(true);
        }
Example #8
0
        public void OnPlayerUseWorldItemSecondary(object secondaryResult)
        {
            WIListResult dialogResult = secondaryResult as WIListResult;

            switch (dialogResult.SecondaryResult)
            {
            case "Drink":
                if (!CanBuyDrink)
                {
                    if (gBartenderSpeech == null)
                    {
                        gBartenderSpeech = new Speech();
                    }
                    gBartenderSpeech.Text = "That's enough for one night, {lad/lass}.";
                    worlditem.Get <Talkative>().SayDTS(gBartenderSpeech);
                }
                else
                {
                    if (Player.Local.Inventory.InventoryBank.TryToRemove(PricePerDrink))
                    {
                        Profile.Get.CurrentGame.Character.Rep.GainGlobalReputation(1);
                        //spawn a cup and put some mead in it
                        WorldItem cup = null;
                        if (WorldItems.CloneRandomFromCategory("BartenderCups", WIGroups.Get.World, out cup))
                        {
                            cup.Initialize();
                            LiquidContainer container = null;
                            if (cup.Is <LiquidContainer>(out container))
                            {
                                container.State.Contents.CopyFrom(BartenderDrinkContents);
                                container.State.Contents.InstanceWeight = container.State.Capacity;
                            }
                            //try to equip it in the player's hands
                            Player.Local.Inventory.TryToEquip(cup);
                        }
                        State.NumTimesBoughtDrink++;
                        State.NumTimesBoughtDrinkTonight++;
                        State.LastTimeBoughtDrink = WorldClock.AdjustedRealTime;
                    }
                }
                break;

            case "Round":
                if (Player.Local.Inventory.InventoryBank.TryToRemove(PricePerRound))
                {
                    if (gBartenderSpeech == null)
                    {
                        gBartenderSpeech = new Speech();
                    }
                    gBartenderSpeech.Text = "Looks like this round's on {PlayerFirstName}!";
                    worlditem.Get <Talkative>().SayDTS(gBartenderSpeech);
                    Profile.Get.CurrentGame.Character.Rep.GainGlobalReputation(5);
                    State.NumTimesBoughtRound++;
                    State.LastTimeBoughtRound = WorldClock.AdjustedRealTime;
                }
                break;

            default:
                break;
            }
        }