private void DestroyLoot(BaseEntity entity)
            {
                if (entity == null)
                {
                    return;
                }

                StorageContainer container = entity.GetComponent <StorageContainer>();

                if (container != null)
                {
                    ins.ClearContainer(entity);
                    container.DieInstantly();
                }

                JunkPile junkPile = entity.GetComponent <JunkPile>();

                if (junkPile != null)
                {
                    for (int y = 0; y < junkPile.spawngroups.Length; y++)
                    {
                        junkPile.spawngroups[y].Clear();
                    }
                    junkPile.SinkAndDestroy();
                }
            }
Пример #2
0
        public ScientistJunkpileContext(HTNPlayer body, ScientistJunkpileDomain domain)
        {
            int length = System.Enum.GetValues(typeof(Facts)).Length;

            if (this._worldState == null || this._worldState.Length != length)
            {
                this._worldState         = new byte[length];
                this._previousWorldState = new byte[length];
                if (ScientistJunkpileContext._worldStateChanges == null)
                {
                    ScientistJunkpileContext._worldStateChanges = new Stack <WorldStateInfo> [length];
                    for (int index = 0; index < length; ++index)
                    {
                        ScientistJunkpileContext._worldStateChanges[index] = new Stack <WorldStateInfo>(5);
                    }
                }
            }
            this._decompositionScore = int.MaxValue;
            this.Body      = body;
            this.Domain    = domain;
            this.PlanState = (PlanStateType)0;
            if (this.Memory == null || this.Memory.ScientistJunkpileContext != this)
            {
                this.Memory = new ScientistJunkpileMemory(this);
            }
            if (!Object.op_Equality((Object)this.Location, (Object)null))
            {
                return;
            }
            float num = float.MaxValue;

            foreach (AiLocationManager manager in AiLocationManager.Managers)
            {
                Vector3 vector3      = Vector3.op_Subtraction(((Component)manager).get_transform().get_position(), ((Component)this.Body).get_transform().get_position());
                float   sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude();
                if ((double)sqrMagnitude < (double)num)
                {
                    num           = sqrMagnitude;
                    this.Location = manager;
                }
            }
            if (!Object.op_Inequality((Object)this.Location, (Object)null))
            {
                return;
            }
            this.Junkpile = (JunkPile)((Component)this.Location).GetComponent <JunkPile>();
        }
        public ScientistJunkpileContext(HTNPlayer body, ScientistJunkpileDomain domain)
        {
            int length = Enum.GetValues(typeof(Facts)).Length;

            if (this._worldState == null || (int)this._worldState.Length != length)
            {
                this._worldState         = new byte[length];
                this._previousWorldState = new byte[length];
                if (ScientistJunkpileContext._worldStateChanges == null)
                {
                    ScientistJunkpileContext._worldStateChanges = new Stack <WorldStateInfo> [length];
                    for (int i = 0; i < length; i++)
                    {
                        ScientistJunkpileContext._worldStateChanges[i] = new Stack <WorldStateInfo>(5);
                    }
                }
            }
            this._decompositionScore = 2147483647;
            this.Body      = body;
            this.Domain    = domain;
            this.PlanState = PlanStateType.NoPlan;
            if (this.Memory == null || this.Memory.ScientistJunkpileContext != this)
            {
                this.Memory = new ScientistJunkpileMemory(this);
            }
            if (this.Location == null)
            {
                float single = Single.MaxValue;
                foreach (AiLocationManager manager in AiLocationManager.Managers)
                {
                    Vector3 vector3 = manager.transform.position - this.Body.transform.position;
                    float   single1 = vector3.sqrMagnitude;
                    if (single1 >= single)
                    {
                        continue;
                    }
                    single        = single1;
                    this.Location = manager;
                }
                if (this.Location != null)
                {
                    this.Junkpile = this.Location.GetComponent <JunkPile>();
                }
            }
        }
        public void OnEventFinished(string zoneId)
        {
            List <BaseEntity> entities;

            if (!spawnedContainers.TryGetValue(zoneId, out entities))
            {
                return;
            }

            for (int i = entities.Count - 1; i >= 0; i--)
            {
                BaseEntity entity = entities[i];

                if (entity != null && !entity.IsDestroyed)
                {
                    StorageContainer container = entity.GetComponent <StorageContainer>();
                    if (container != null)
                    {
                        ClearContainer(entity);
                        container.Die(new HitInfo(container, container, Rust.DamageType.Explosion, 1000f));
                    }

                    JunkPile junkPile = entity.GetComponent <JunkPile>();
                    if (junkPile != null)
                    {
                        for (int y = 0; y < junkPile.spawngroups.Length; y++)
                        {
                            junkPile.spawngroups[y].Clear();
                        }
                        junkPile.SinkAndDestroy();
                    }
                }
            }

            spawnedContainers[zoneId].Clear();
        }
Пример #5
0
 public override string GetInteractionName(Sim actor, JunkPile target, InteractionObjectPair iop)
 {
     return(base.GetInteractionName(actor, target, new InteractionObjectPair(sOldSingleton, target)));
 }
Пример #6
0
 public override string GetInteractionName(Sim actor, JunkPile target, InteractionObjectPair iop)
 {
     return base.GetInteractionName(actor, target, new InteractionObjectPair(sOldSingleton, target));
 }
Пример #7
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            base.PrivateUpdate(frame);

            InventingSkill skill = Sim.SkillManager.GetElement(SkillNames.Inventing) as InventingSkill;

            List <InventionWorkbench> benches = new List <InventionWorkbench>();
            List <InventionWorkbench> empties = new List <InventionWorkbench>();

            foreach (Lot lot in ManagerLot.GetOwnedLots(Sim))
            {
                foreach (InventionWorkbench bench in lot.GetObjects <InventionWorkbench>())
                {
                    if (bench.InUse)
                    {
                        continue;
                    }

                    if (bench.mIsMakingFrankensim)
                    {
                        continue;
                    }

                    if (bench.mInventionProgress > 0)
                    {
                        if (skill == null)
                        {
                            continue;
                        }

                        if (!skill.KnownInventions.Contains(bench.mInventionKey))
                        {
                            continue;
                        }

                        benches.Add(bench);
                    }
                    else
                    {
                        empties.Add(bench);
                    }
                }
            }

            if (benches.Count == 0)
            {
                benches.AddRange(empties);

                if (benches.Count == 0)
                {
                    IncStat("No Bench");
                    return(false);
                }
            }

            int minimumScrap   = InventionWorkbench.kNumScrapsPerDiceRoll * 10;
            int inventoryScrap = Inventories.InventoryFindAll <Scrap>(Sim).Count;

            if (inventoryScrap < minimumScrap)
            {
                List <JunkPile> piles = new List <JunkPile>();
                foreach (JunkPile pile in Sims3.Gameplay.Queries.GetObjects <JunkPile>())
                {
                    if (pile.IsEmpty)
                    {
                        continue;
                    }

                    if (pile.LotCurrent == Sim.LotHome)
                    {
                        piles.Add(pile);
                    }
                    else if (pile.LotCurrent == null)
                    {
                        continue;
                    }
                    else if (pile.LotCurrent.IsCommunityLot)
                    {
                        piles.Add(pile);
                    }
                }

                bool success = false;

                while (piles.Count > 0)
                {
                    JunkPile junkChoice = RandomUtil.GetRandomObjectFromList(piles);
                    piles.Remove(junkChoice);

                    if (!Situations.PushInteraction(this, Sim, junkChoice, DigThroughEx.Singleton))
                    {
                        break;
                    }

                    IncStat("Push Dig Through");

                    success = true;
                }

                if (!success)
                {
                    Money.AdjustFunds(Sim, "BuyItem", -InventionWorkbench.Restock.GetScrapCost(minimumScrap - inventoryScrap));

                    AddStat("Buy Scrap", minimumScrap - inventoryScrap);

                    CreateScrap(Sim.CreatedSim, minimumScrap - inventoryScrap);
                }
                else
                {
                    return(true);
                }
            }

            InventionWorkbench choice = RandomUtil.GetRandomObjectFromList(benches);

            if (choice.mInventionProgress > 0)
            {
                IncStat("Try Continue");

                if (Situations.PushInteraction(this, Sim, choice, MakeInventionEx.Singleton))
                {
                    return(true);
                }

                IncStat("Continue Fail");
                return(false);
            }
            else
            {
                if ((skill != null) && (skill.GetUndiscoveredInventions().Count == 0x0) && (skill.ReachedMaxLevel()))
                {
                    IncStat("Try Start New");

                    if (Situations.PushInteraction(this, Sim, choice, MakeInventionEx.Singleton))
                    {
                        return(true);
                    }

                    IncStat("Start New Fail");
                    return(false);
                }
                else
                {
                    if ((skill == null) || (skill.KnownInventions.Count == 0) || (RandomUtil.RandomChance(25)))
                    {
                        IncStat("Try Invent");

                        if (Situations.PushInteraction(this, Sim, choice, new InventionWorkbench.Invent.Definition()))
                        {
                            return(true);
                        }

                        IncStat("Invent Fail");
                        return(false);
                    }
                    else
                    {
                        IncStat("Try Start New");

                        if (Situations.PushInteraction(this, Sim, choice, MakeInventionEx.Singleton))
                        {
                            return(true);
                        }

                        IncStat("Start New Fail");
                        return(false);
                    }
                }
            }
        }