public virtual bool TakeDamage(WIMaterialType materialType, Vector3 damagePoint, float attemptedDamage, Vector3 attemptedForce, string damageSource, out float actualDamage, out bool isDead)
        {
            actualDamage       = attemptedDamage;
            isDead             = false;
            State.TotalDamage += actualDamage;

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

            if (State.SpawnOnDamaage && State.TotalDamage >= State.SpawnDamageMinimum)                                          //reset
            {
                State.TotalDamage = 0f;
                //spawn a thing
                WorldItem worlditem = null;
                if (WorldItems.CloneRandomFromCategory(State.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);
                    FXManager.Get.SpawnFX(worlditem.tr, "DrawAttentionToItem");
                    worlditem.GetOrAdd <DespawnOnPlayerLeave>();
                }
            }
            return(true);
        }
Exemple #2
0
        public void OnTriggerExit(Collider other)
        {
            if (VisitableLocation == null || !VisitableLocation.Initialized)
            {
                return;
            }

            if (other.isTrigger)
            {
                return;
            }

            if (other.gameObject.layer == Globals.LayerNumPlayer)
            {
                VisitableLocation.PlayerLeave();
                if (VisitableLocation.PlayerOnly)
                {
                    return;
                }
            }
            //do we care about any world items?
            if (other.gameObject.layer == Globals.LayerNumWorldItemActive && VisitableLocation.ItemsOfInterest.Count > 0)
            {
                mIoiCheck = null;
                if (WorldItems.GetIOIFromCollider(other, out mIoiCheck) && mIoiCheck.IOIType == ItemOfInterestType.WorldItem && mIoiCheck.worlditem.HasAtLeastOne(VisitableLocation.ItemsOfInterest))
                {
                    VisitableLocation.ItemOfInterestLeave(mIoiCheck.worlditem);
                }
            }
        }
Exemple #3
0
        protected IEnumerator OnSetRemovedMode()
        {
            yield return(null);

            try {
                //if we're going into world mode then we're not in the stack any more
                OnRemoveFromStack.SafeInvoke();
                //tell our group that we're permanently gone
                Group.RemoveChildItemFromGroup(this);
                //this will call OnRemovedFromGroup
                OnRemovedFromGame.SafeInvoke();
                //make sure to save the state so we know it's removed!
                PrepareToUnload();
            } catch (Exception e) {
                Debug.LogError("Exception while removing object: " + e.ToString());
            }

            while (!ReadyToUnload)
            {
                yield return(null);
            }

            BeginUnload();

            while (!FinishedUnloading)
            {
                yield return(null);
            }
            yield return(null);

            WorldItems.Unload(this);
        }
Exemple #4
0
        public override void PopulateOptionsList(System.Collections.Generic.List <GUIListOption> options, List <string> message)
        {
            if (mGenericLiquid == null)
            {
                if (!WorldItems.GetRandomGenericWorldItemFromCatgeory(State.LiquidCategory, out mGenericLiquid))
                {
                    return;
                }
            }

            mOptionsListItems.Clear();
            LiquidContainer liquidContainer = null;

            if (Player.Local.Tool.IsEquipped && Player.Local.Tool.worlditem.Is <LiquidContainer>(out liquidContainer))
            {
                options.Add(new GUIListOption("Fill " + liquidContainer.worlditem.DisplayName, "Fill"));
            }
//			Dictionary <int,IWIBase> QuickslotItems = Player.Local.Inventory.QuickslotItems;
//			foreach (KeyValuePair <int,IWIBase> quickslotItem in QuickslotItems) {
//				IWIBase qsItem = quickslotItem.Value;
//				//foreach liquid container in quickslots
//				if (qsItem.Is <LiquidContainer> () && qsItem.IsWorldItem) {
//					//TODO make sure we can actually fill the item
//					options.Add (new GUIListOption ("Fill " + qsItem.DisplayName, qsItem.FileName));
//					mOptionsListItems.Add (qsItem.FileName, qsItem);
//				}
//			}

            options.Add(new GUIListOption("Drink " + mGenericLiquid.DisplayName, "Drink"));
        }
        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;

            Books.Get.InitializeBookAvatarGameObject(doppleganger, item.StackName, subcat);
            WorldItems.ApplyDopplegangerMode(item, doppleganger, mode, scaleMultiplier);
            return(doppleganger);
        }
Exemple #6
0
        public void OnTriggerEnter(Collider other)
        {
            if (other.isTrigger)
            {
                return;
            }

            if (WorldItems.GetIOIFromCollider(other, out LastItemOfInterest) &&
                Flags.Check((uint)TriggeredBy, (uint)LastItemOfInterest.IOIType, Flags.CheckType.MatchAny))
            {
                trigger.TryToTrigger();
            }
        }
Exemple #7
0
        public void OnCollisionEnter(Collision other)
        {
            if (other.gameObject.collider.isTrigger)
            {
                return;
            }

            if (Props.HasThorns)
            {
                if (WorldItems.GetIOIFromCollider(other.collider, out Plants.Get.ThornDamage.Target))
                {
                    DamageManager.Get.SendDamage(Plants.Get.ThornDamage);
                }
            }
        }
        //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);
        }
Exemple #9
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);
        }
Exemple #10
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");
        }
        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);
        }
Exemple #12
0
 protected override void HandleEncounter(UnityEngine.Collider other)
 {
     //this will cover most cases including the player
     mlisteningItemCheck = (IListener)other.GetComponent(typeof(IListener));
     if (mlisteningItemCheck == null)
     {
         //whoops, we have to do some heavy lifting
         //see if it's a world item
         mIoiCheck      = null;
         mlistenerCheck = null;
         if (WorldItems.GetIOIFromCollider(other, out mIoiCheck) && mIoiCheck.IOIType == ItemOfInterestType.WorldItem && mIoiCheck.worlditem.Is <Listener>(out mlistenerCheck))
         {
             mlisteningItemCheck = mlistenerCheck;
         }
     }
     //unlike the visibility bubble
     //listeners are responsible for figuring out whether they can hear the item
     //so just add it to the list and it'll be pushed in OnUpdateAwareness
     Listeners.SafeAdd(mlisteningItemCheck);
 }
Exemple #13
0
        public void Initialize(Projectile launchedProjectile, Transform actionPoint, Weapon fromWeapon, float initialLaunchForce)
        {
            FromWeapon         = fromWeapon;
            LaunchedProjectile = launchedProjectile;
            TrajectoryObject   = new GameObject("TrajectoryObject");
            InitialLaunchForce = initialLaunchForce;

            //align the trajectory object with the launched object
            //disregard the x rotation, we only want 2D orientation
            //then set parent to null;
            //finally, parent the launched projectile under this object
            //its 2D motion will now translate into 3D space
            TrajectoryObject.transform.position = actionPoint.position;
            Vector3 actionPointRotation = actionPoint.transform.rotation.eulerAngles;

            TrajectoryObject.transform.rotation = Quaternion.Euler(actionPointRotation.x, actionPointRotation.y, 0f);
            ProjectileDoppleganger       = WorldItems.GetDoppleganger(launchedProjectile.worlditem, TrajectoryObject.transform, ProjectileDoppleganger);
            ProjectileDoppleganger.layer = Globals.LayerNumWorldItemActive;
            //use the trajectory's forward vector to determine the angle

            Trail              = ProjectileDoppleganger.AddComponent <TrailRenderer>();
            Trail.startWidth   = 0.01f;
            Trail.endWidth     = 0.5f;
            Trail.autodestruct = true;
            Trail.time         = 0.65f;
            Trail.material     = Mats.Get.TrailRendererMaterial;

            InitialAngleInDegrees = Mathf.Acos(Vector3.Dot(TrajectoryObject.transform.forward, actionPoint.forward)).Clean();

            //create a damage package
            mDamage                = new DamagePackage();
            mDamage.DamageSent     = LaunchedProjectile.DamagePerHit * initialLaunchForce;
            mDamage.SenderMaterial = LaunchedProjectile.worlditem.Props.Global.MaterialType;
            mDamage.Source         = fromWeapon.worlditem;
            mDamage.SenderName     = fromWeapon.worlditem.DisplayName;

            Current3DPosition = ProjectileDoppleganger.transform.position;

            mInitialized = true;
        }
Exemple #14
0
        public void OnCollisionEnter(Collision col)
        {
            if (col.gameObject.CompareTag(Globals.TagGroundTerrain))
            {
                return;
            }

            if (WorldItems.GetIOIFromGameObject(col.gameObject, out mIoi))
            {
                if (gDamagePackage == null)
                {
                    gDamagePackage                = new DamagePackage();
                    gDamagePackage.DamageSent     = Globals.DamageOnRockslideHit;
                    gDamagePackage.SenderMaterial = WIMaterialType.Stone;
                    gDamagePackage.Source         = this;
                }
                gDamagePackage.ForceSent = col.relativeVelocity.magnitude * 0.1f;
                gDamagePackage.Point     = tr.position;
                gDamagePackage.Target    = mIoi;
                DamageManager.Get.SendDamage(gDamagePackage);
            }
        }
Exemple #15
0
        public void OnTriggerEnter(Collider other)
        {
            if (mStartedDestroying || mDestroyed)
            {
                return;
            }

            IItemOfInterest ioi = null;

            if (WorldItems.GetIOIFromCollider(other, out ioi))
            {
                Listener listener = null;
                if (ioi.IOIType == ItemOfInterestType.WorldItem && ioi.worlditem.Is <Listener> (out listener) && !Listeners.Contains(listener))
                {
                    Listeners.Add(listener);
                    if (!string.IsNullOrEmpty(ParentSpeech.OnAudibleCommand))
                    {
                        listener.HearCommand(this, ParentSpeech.OnAudibleCommand);
                    }
                }
            }
        }
Exemple #16
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;
            }
        }
Exemple #17
0
        //this editor function does a bunch of sanity-check stuff
        //to make sure that the foodstuff is set up properly
        public override void InitializeTemplate()
        {
            mCurrentProps = null;
            if (State.PotentialProps.Count > 0)
            {
                WIStates states = null;
                if (gameObject.HasComponent <WIStates>(out states))
                {
                    for (int i = 0; i < State.PotentialProps.Count; i++)
                    {
                        if (State.PotentialProps[i].Name == states.DefaultState)
                        {
                            mCurrentProps = State.PotentialProps[i];
                            break;
                        }
                    }
                }
                if (mCurrentProps == null)
                {
                    for (int i = 0; i < State.PotentialProps.Count; i++)
                    {
                        if (State.PotentialProps[i].Name == "Raw")
                        {
                            mCurrentProps = State.PotentialProps[i];
                            break;
                        }
                    }
                }
                if (mCurrentProps == null)
                {
                    //f**k it
                    mCurrentProps = State.PotentialProps[0];
                }
            }

            return;

            if (Application.isPlaying)
            {
                return;
            }

            if (worlditem.Props.Global.MaterialType != WIMaterialType.Plant && worlditem.Props.Global.MaterialType != WIMaterialType.Flesh)
            {
                worlditem.Props.Global.MaterialType = WIMaterialType.Food;
            }

            if (State.PotentialProps.Count == 0)
            {
                Debug.Log("Didn't find any potential food props, creating 'Raw' now");
                FoodStuffProps props = new FoodStuffProps();
                props.Name          = "Raw";
                props.Type          = FoodStuffEdibleType.Edible;
                props.HungerRestore = PlayerStatusRestore.B_OneFifth;
                props.Perishable    = false;
                State.PotentialProps.Add(props);
            }
            else
            {
                Debug.Log("Found " + State.PotentialProps.Count.ToString() + " props");
            }

            if (worlditem.States != null)
            {
                Debug.Log("worlditem has states");
                foreach (WIState state in worlditem.States.States)
                {
                    bool foundAccompanyingFoodState = false;
                    foreach (FoodStuffProps props in this.State.PotentialProps)
                    {
                        if (props.Name == state.Name)
                        {
                            foundAccompanyingFoodState = true;
                        }
                    }

                    if (!foundAccompanyingFoodState)
                    {
                        Debug.Log("Didn't find accompanying food state in " + worlditem.name + " for worlditem state: " + state.Name + ", adding now");
                        FoodStuffProps newProps = new FoodStuffProps();
                        newProps.Name = state.Name;
                        //there are some common states that we can make guesses for
                        switch (state.Name)
                        {
                        case "Rotten":
                            newProps.Type            = FoodStuffEdibleType.Edible;
                            newProps.HungerRestore   = PlayerStatusRestore.B_OneFifth;
                            newProps.ConditionChance = 0.95f;
                            newProps.ConditionName   = "FoodPoisoning";
                            newProps.Perishable      = false;
                            break;

                        case "Raw":
                            newProps.Type          = FoodStuffEdibleType.Edible;
                            newProps.HungerRestore = PlayerStatusRestore.C_TwoFifths;
                            newProps.Perishable    = true;
                            break;

                        case "Cooked":
                            newProps.Type          = FoodStuffEdibleType.Edible;
                            newProps.HungerRestore = PlayerStatusRestore.F_Full;
                            newProps.Perishable    = true;
                            break;

                        case "Burned":
                            newProps.Type          = FoodStuffEdibleType.Edible;
                            newProps.HungerRestore = PlayerStatusRestore.B_OneFifth;
                            newProps.Perishable    = false;
                            break;

                        case "Preserved":
                        case "Dried":
                            newProps.Type          = FoodStuffEdibleType.Edible;
                            newProps.HungerRestore = PlayerStatusRestore.D_ThreeFifths;
                            newProps.Perishable    = false;
                            break;

                        default:
                            newProps.Type = FoodStuffEdibleType.None;                                                                                                    //make it inedible
                            break;
                        }
                        State.PotentialProps.Add(newProps);
                    }
                }
            }

            bool requiresRottenState = false;

            foreach (FoodStuffProps props in State.PotentialProps)
            {
                if (props.Name == "Raw")
                {
                    bool foundCooked = false;
                    foreach (FoodStuffProps cookedProps in State.PotentialProps)
                    {
                        if (cookedProps.Name == "Cooked")
                        {
                            foundCooked           = true;
                            props.ConditionName   = "FoodPoisoning";
                            props.ConditionChance = 0.25f;
                            break;
                        }
                    }
                    if (!foundCooked)
                    {
                        props.ConditionName   = string.Empty;
                        props.ConditionChance = 0f;
                    }
                    else
                    {
                        gameObject.GetOrAdd <Photosensitive>();
                    }
                }


                requiresRottenState |= props.Perishable;
                if (props.Name == "Rotten")
                {
                    requiresRottenState |= true;
                }
            }

            //check our states against our props and make sure there's parity
            if (State.PotentialProps.Count > 1)
            {
                if (worlditem.States == null)
                {
                    worlditem.States = worlditem.gameObject.AddComponent <WIStates>();
                    worlditem.InitializeTemplate();
                    return;
                }

                //now attempt to match our props up against our states and make sure there's parity
                foreach (FoodStuffProps props in State.PotentialProps)
                {
                    WIState existingState          = null;
                    bool    foundAccompanyingState = false;
                    foreach (WIState state in worlditem.States.States)
                    {
                        if (state.Name == props.Name)
                        {
                            if (!foundAccompanyingState)
                            {
                                existingState          = state;
                                foundAccompanyingState = true;
                            }
                            if (state.Name == "Rotten")
                            {
                                requiresRottenState = true;
                            }
                        }
                    }

                    if (!foundAccompanyingState)
                    {
                        WIState newState = null;
                        Debug.Log("Didn't find accompanying worlditem state in " + worlditem.name + " for food state: " + props.Name + ", adding now");
                        if (worlditem.States.States.Count == 0)
                        {
                            //create a state from the base object - this will also strip the base object of renderers etc.
                            newState = WorldItems.CreateTemplateState(worlditem, props.Name, worlditem.gameObject);
                        }
                        else
                        {
                            //otherwise just make a copy from the first existing state, we'll clean it up later
                            newState = WorldItems.CreateTemplateState(worlditem, props.Name, worlditem.States.States[0].StateObject);
                        }
                        existingState = newState;
                    }

                    if (existingState != null)
                    {
                        existingState.IsInteractive     = true;
                        existingState.Suffix            = props.Name;
                        existingState.StackName         = props.Name + " " + worlditem.Props.Name.StackName;
                        existingState.UnloadWhenStacked = true;
                        existingState.CanEnterInventory = true;
                        existingState.CanBePlaced       = true;
                        existingState.CanBeDropped      = true;
                        existingState.CanBeCarried      = true;

                        switch (existingState.Name)
                        {
                        case "Raw":
                            existingState.IsPermanent = false;
                            break;

                        case "Cooked":
                            existingState.IsPermanent = true;
                            existingState.FXOnChange  = "FoodstuffCookedSmoke";
                            break;

                        case "Rotten":
                            existingState.IsPermanent = true;
                            break;

                        case "Burned":
                            existingState.IsPermanent = true;
                            existingState.FXOnChange  = "FoodstuffBurnedSmoke";
                            break;

                        case "Preserved":
                        case "Dried":
                            existingState.IsPermanent = true;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            else
            {
                Debug.Log("Only 1 foodstuff props so no need for states");
                if (worlditem.States != null && worlditem.States.States.Count == 0)
                {
                    GameObject.DestroyImmediate(worlditem.States);
                }
            }

            if (requiresRottenState)
            {
                Debug.Log("Requires perishable, checking now");
                bool hasRottenState = false;
                bool hasRawState    = false;
                foreach (FoodStuffProps props in State.PotentialProps)
                {
                    if (props.Name == "Raw")
                    {
                        props.Perishable = true;
                        hasRawState      = true;
                    }
                    else if (props.Name == "Rotten")
                    {
                        hasRottenState = true;
                    }
                }

                if (!hasRawState)
                {
                    FoodStuffProps newProps = new FoodStuffProps();
                    newProps.Name          = "Raw";
                    newProps.Perishable    = true;
                    newProps.Type          = FoodStuffEdibleType.Edible;
                    newProps.HungerRestore = PlayerStatusRestore.C_TwoFifths;
                    newProps.Perishable    = true;
                    State.PotentialProps.Add(newProps);
                }
                if (!hasRottenState)
                {
                    FoodStuffProps newProps = new FoodStuffProps();
                    newProps.Name            = "Rotten";
                    newProps.Type            = FoodStuffEdibleType.Edible;
                    newProps.HungerRestore   = PlayerStatusRestore.C_TwoFifths;
                    newProps.ConditionChance = 0.5f;
                    newProps.ConditionName   = "FoodPoisoning";
                    State.PotentialProps.Add(newProps);
                }
            }
            else
            {
                Debug.Log("Didn't require rotten state");
            }

            if (worlditem.States != null)
            {
                bool foundDefaultState = false;
                foreach (WIState state in worlditem.States.States)
                {
                    if (worlditem.States.DefaultState == state.Name)
                    {
                        foundDefaultState = true;
                        break;
                    }
                }

                if (!foundDefaultState)
                {
                    Debug.Log("Didin't find default state " + worlditem.States.DefaultState + ", setting to Raw");
                    worlditem.States.DefaultState = "Raw";
                }
            }

            if (worlditem.HasStates)
            {
                //now that the worlditem has states it shouldn't have its own mesh stuff
                //destroy the me now
                MeshFilter worldItemMF = null;
                if (worlditem.gameObject.HasComponent <MeshFilter>(out worldItemMF))
                {
                    GameObject.DestroyImmediate(worldItemMF);
                }
                MeshRenderer worldItemMR = null;
                if (worlditem.gameObject.HasComponent <MeshRenderer>(out worldItemMR))
                {
                    GameObject.DestroyImmediate(worldItemMR);
                }
                if (worlditem.collider != null)
                {
                    GameObject.DestroyImmediate(worlditem.collider);
                }
            }

            foreach (FoodStuffProps props in State.PotentialProps)
            {
                if (props.IsLiquid)
                {
                    props.EatFoodSound = "DrinkLiquidGeneric";
                }
                else
                {
                    props.EatFoodSound = "EatFoodGeneric";
                }
            }

            mCurrentProps = null;
            base.InitializeTemplate();
        }
Exemple #18
0
        public void Update()
        {
            if (!mInitialized)
            {
                return;
            }

            if (Cooldown)
            {
                if (Trail == null || LaunchedProjectile == null)
                {
                    //trail has self-destructed
                    enabled = false;
                    GameObject.Destroy(this);
                    GameObject.Destroy(ProjectileDoppleganger);
                }
                else
                {
                    ProjectileDoppleganger.transform.position = LaunchedProjectile.worlditem.tr.position;
                    ProjectileDoppleganger.transform.rotation = LaunchedProjectile.worlditem.tr.rotation;
                }
                return;
            }

            //send the projectile along the parameter
            CurrentTime   += WorldClock.RTDeltaTime;
            Last3DPosition = Current3DPosition;
            UpdatePositionAlongTrajectory(CurrentTime);
            ProjectileDoppleganger.transform.localPosition = new Vector3(0f, Current2DPosition.y, Current2DPosition.x);
            Current3DPosition = ProjectileDoppleganger.transform.position;
            ProjectileDoppleganger.transform.position = Current3DPosition;
            CurrentForce       = Vector3.Distance(Current3DPosition, Last3DPosition);
            CurrentOrientation = (Current3DPosition - Last3DPosition).normalized;
            if (CurrentOrientation != Vector3.zero)
            {
                ProjectileDoppleganger.transform.rotation = Quaternion.LookRotation(CurrentOrientation, Vector3.up);
            }

            //let worlditems in our potential path know that the need to be 'active'
            //otherwise the projectile might go right through them
            WorldItems.Get.SetActiveStateOverride(Current3DPosition, CurrentForce * 2);

            RaycastHit hitInfo;

            if (Physics.Linecast(Last3DPosition, Current3DPosition, out hitInfo, Globals.LayersActive))
            {
                IItemOfInterest target   = null;
                BodyPart        bodyPart = null;
                if (!hitInfo.collider.isTrigger)
                {
                    if (WorldItems.GetIOIFromCollider(hitInfo.collider, out target, out bodyPart))
                    {
                        if (target.IOIType == ItemOfInterestType.Player)
                        {
                            //Debug.Log ("Was player");
                            return;
                        }
                        mDamage.Point     = hitInfo.point;
                        mDamage.ForceSent = (CurrentForce + InitialLaunchForce) / 2;
                        mDamage.Target    = target;
                        DamageManager.Get.SendDamage(mDamage, bodyPart);
                    }
                    LaunchedProjectile.worlditem.tr.position = ProjectileDoppleganger.transform.position;
                    LaunchedProjectile.worlditem.tr.rotation = ProjectileDoppleganger.transform.rotation;
                    LaunchedProjectile.OnCollide(hitInfo.collider, hitInfo.point);
                    OnReachEnd();
                }
            }
        }
Exemple #19
0
        public void OnCollectiveThoughtStart()
        {
            if (mDestroyed)
            {
                return;
            }

            IItemOfInterest itemOfInterest = character.CurrentThought.CurrentItemOfInterest;

            switch (itemOfInterest.IOIType)
            {
            case ItemOfInterestType.Player:
                if (worlditem.Is <Hostile> (out hostile) && hostile.PrimaryTarget == itemOfInterest)
                {
                    //don't need to do anything else, we're already attacking the player
                    character.CurrentThought.Should(IOIReaction.IgnoreIt);
                    Debug.Log("Already hostile, not attacking player");
                    return;
                }
                else
                {
                    if (WorldItems.HasLineOfSight(character.Body.Transforms.HeadTop.position, itemOfInterest, ref gTargetPosition, ref gHitPosition, out gHitIOI))
                    {
                        if (ParentCamp.PlayerVisitingCamp)
                        {
                            ParentCamp.HasAttackedPlayerRecently = true;
                            Debug.Log("Player is visiting camp, time to kill the player");
                            character.CurrentThought.Should(IOIReaction.KillIt);
                            character.CurrentThought.Should(IOIReaction.KillIt);
                            character.CurrentThought.Should(IOIReaction.KillIt);
                        }
                        else
                        {
                            Debug.Log("Player is NOT visiting camp");
                            character.CurrentThought.Should(IOIReaction.WatchIt);
                            //if the player is on the outskirts then warn the player
                            if (ParentCamp.HasAttackedPlayerRecently && !ParentCamp.HasTauntedPlayerRecently)
                            {
                                ParentCamp.HasTauntedPlayerRecently = true;
                                Talkative talkative = worlditem.Get <Talkative> ();
                                Motile    motile    = worlditem.Get <Motile> ();
                                //get the node closest to the bandit
                                talkative.GiveSpeech(ParentCamp.State.SpeechTaunt, motile.LastOccupiedNode);
                            }
                            else if (!ParentCamp.HasWarnedPlayerRecently)
                            {
                                Debug.Log("Warning player with speech" + ParentCamp.State.SpeechWarning);
                                ParentCamp.HasWarnedPlayerRecently = true;
                                Talkative talkative = worlditem.Get <Talkative> ();
                                Motile    motile    = worlditem.Get <Motile> ();
                                //get the node closest to the bandit
                                talkative.GiveSpeech(ParentCamp.State.SpeechWarning, motile.LastOccupiedNode);
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("Didn't have line of sight");
                    }
                }
                break;

            case ItemOfInterestType.Scenery:
            default:
                character.CurrentThought.Should(IOIReaction.IgnoreIt);
                break;

            case ItemOfInterestType.WorldItem:
                if (worlditem.Is <Hostile> (out hostile))
                {
                    //don't need to do anything else, we're already attacking the player
                    character.CurrentThought.Should(IOIReaction.IgnoreIt);
                    return;
                }
                else if (itemOfInterest.worlditem.Is <Creature> ())
                {
                    Debug.Log("Voting to kill creature " + itemOfInterest.worlditem.name + " in bandit");
                    character.CurrentThought.Should(IOIReaction.KillIt);
                    character.CurrentThought.Should(IOIReaction.KillIt);
                }
                else
                {
                    character.CurrentThought.Should(IOIReaction.WatchIt);
                }
                break;
            }
        }