public GameObject FindThreat()
        {
            threats.Clear();
            ListPool <ScenePartitionerEntry, ThreatMonitor> .PooledList pooledList = ListPool <ScenePartitionerEntry, ThreatMonitor> .Allocate();

            Extents extents = new Extents(Grid.PosToCell(eggToProtect), maxThreatDistance);

            GameScenePartitioner.Instance.GatherEntries(extents, GameScenePartitioner.Instance.attackableEntitiesLayer, pooledList);
            for (int i = 0; i < pooledList.Count; i++)
            {
                ScenePartitionerEntry scenePartitionerEntry = pooledList[i];
                FactionAlignment      factionAlignment      = scenePartitionerEntry.obj as FactionAlignment;
                if (!((UnityEngine.Object)factionAlignment.transform == (UnityEngine.Object)null) && !((UnityEngine.Object)factionAlignment == (UnityEngine.Object)alignment) && factionAlignment.IsAlignmentActive() && navigator.CanReach(factionAlignment.attackable))
                {
                    bool  flag     = false;
                    Tag[] allyTags = base.def.allyTags;
                    foreach (Tag tag in allyTags)
                    {
                        if (factionAlignment.HasTag(tag))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        threats.Add(factionAlignment);
                    }
                }
            }
            pooledList.Recycle();
            return(PickBestTarget(threats));
        }
                public void EvaluateBuddiesAndFiends()
                {
                    //PUtil.LogDebug("EvaluateBuddiesAndFiends");
                    this.fiends.Clear();
                    //this.buddies.Clear();

                    //PUtil.LogDebug(("Creature : {0}, pos {1}").F(this.gameObject.name, Grid.PosToCell((KMonoBehaviour)this.navigator)));
                    Extents gridCheck = new Extents(Grid.PosToCell((KMonoBehaviour)this.navigator), maxThreatDistance);

                    buddiesCount = PositionMonitor.Instance.CountEntries(gridCheck, PositionMonitor.Instance.Layer("DW_Hatches"));
                    //PUtil.LogDebug(("Number of components found: {0}").F(buddiesCount));

                    ListPool <PositionMonitor.PositionMonitorEntry, PositionMonitor> .PooledList entitiesList = ListPool <PositionMonitor.PositionMonitorEntry, PositionMonitor> .Allocate();

                    PositionMonitor.Instance.GatherEntries(gridCheck, PositionMonitor.Instance.Layer("DW_Minions"), entitiesList);
                    //PUtil.LogDebug(("Number of minions found: {0}").F(entitiesList.Count));
                    for (int index = 0; index < entitiesList.Count; ++index)
                    {
                        FactionAlignment cmp = entitiesList[index].m_object.GetComponent <FactionAlignment>();
                        if (cmp != null && this.navigator.CanReach((IApproachable)cmp.attackable) && cmp.GetComponent <MinionBrain>() != null && cmp.GetComponent <MinionBrain>().HasTag(GameTags.Minion))
                        {
                            //PUtil.LogDebug(("Component {0} has tag minion: {1}").F(cmp.name, cmp.GetComponent<MinionBrain>().HasTag(GameTags.Minion)));
                            this.fiends.Add(cmp);
                        }
                    }
                    entitiesList.Recycle();
                }
 public Instance(IStateMachineTarget master, Def def)
     : base(master, def)
 {
     alignment             = master.GetComponent <FactionAlignment>();
     navigator             = master.GetComponent <Navigator>();
     refreshThreatDelegate = RefreshThreat;
 }
示例#4
0
 public Character(int id, string name, FactionAlignment alignment, int locationId)
 {
     _id         = id;
     _name       = name;
     _alignment  = alignment;
     _locationId = locationId;
 }
示例#5
0
    public void AddNewEntry(GameObject representedObject)
    {
        Entry entry = new Entry();

        entry.world_go = representedObject;
        GameObject original   = (!ShouldShowName(representedObject)) ? barsPrefab : nameAndBarsPrefab;
        GameObject gameObject = entry.display_go = Util.KInstantiateUI(original, base.gameObject, true);

        if (worldSpace)
        {
            entry.display_go.transform.localScale = Vector3.one * 0.01f;
        }
        gameObject.name = representedObject.name + " character overlay";
        entry.Name      = representedObject.name;
        entry.refs      = gameObject.GetComponent <HierarchyReferences>();
        entries.Add(entry);
        KSelectable      component  = representedObject.GetComponent <KSelectable>();
        FactionAlignment component2 = representedObject.GetComponent <FactionAlignment>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
            {
                if (component2.Alignment == FactionManager.FactionID.Friendly || component2.Alignment == FactionManager.FactionID.Duplicant)
                {
                    UpdateName(representedObject);
                }
            }
            else
            {
                UpdateName(representedObject);
            }
        }
    }
示例#6
0
                public void Iterate(object target_object)
                {
                    FactionAlignment gameObject = target_object as FactionAlignment;

                    PUtil.LogDebug("Iterate");
                    if (gameObject != null)
                    {
                        PUtil.LogDebug(("Object name: {0}").F(gameObject.name));
                    }
                }
        public GameObject PickBestTarget(List <FactionAlignment> threats)
        {
            float      num    = 1f;
            Vector2    a      = base.gameObject.transform.GetPosition();
            GameObject result = null;
            float      num2   = float.PositiveInfinity;

            for (int num3 = threats.Count - 1; num3 >= 0; num3--)
            {
                FactionAlignment factionAlignment = threats[num3];
                float            num4             = Vector2.Distance(a, factionAlignment.transform.GetPosition()) / num;
                if (num4 < num2)
                {
                    num2   = num4;
                    result = factionAlignment.gameObject;
                }
            }
            return(result);
        }
                public GameObject PickBestThreat()
                {
                    if (this.fiends.Count == 0)
                    {
                        return((GameObject)null);
                    }

                    float      num1       = 1f;
                    Vector2    myPosition = (Vector2)this.gameObject.transform.GetPosition();
                    GameObject gameObject = (GameObject)null;
                    float      num2       = float.PositiveInfinity;

                    for (int index = this.fiends.Count - 1; index >= 0; --index)
                    {
                        FactionAlignment threat = this.fiends[index];
                        float            num3   = Vector2.Distance(myPosition, (Vector2)threat.transform.GetPosition()) / num1;
                        if ((double)num3 < (double)num2)
                        {
                            num2       = num3;
                            gameObject = threat.gameObject;
                        }
                    }
                    return(gameObject);
                }
 public Instance(IStateMachineTarget master, AggroMonitor.Def def) : base(master, def)
 {
     this.alignment = master.GetComponent <FactionAlignment>();
     this.navigator = master.GetComponent <Navigator>();
 }
示例#10
0
    public GameObject CreatePrefab()
    {
        string     name       = DUPLICANTS.MODIFIERS.BASEDUPLICANT.NAME;
        GameObject gameObject = EntityTemplates.CreateEntity(ID, name, true);

        gameObject.AddOrGet <StateMachineController>();
        MinionModifiers modifiers = gameObject.AddOrGet <MinionModifiers>();

        AddMinionAmounts(modifiers);
        AddMinionTraits(name, modifiers);
        gameObject.AddOrGet <MinionBrain>();
        gameObject.AddOrGet <KPrefabID>().AddTag(GameTags.DupeBrain, false);
        gameObject.AddOrGet <Worker>();
        gameObject.AddOrGet <ChoreConsumer>();
        Storage storage = gameObject.AddOrGet <Storage>();

        storage.fxPrefix   = Storage.FXPrefix.PickedUp;
        storage.dropOnLoad = true;
        storage.SetDefaultStoredItemModifiers(new List <Storage.StoredItemModifier>
        {
            Storage.StoredItemModifier.Preserve,
            Storage.StoredItemModifier.Seal
        });
        gameObject.AddOrGet <Health>();
        OxygenBreather oxygenBreather = gameObject.AddOrGet <OxygenBreather>();

        oxygenBreather.O2toCO2conversion  = 0.02f;
        oxygenBreather.lowOxygenThreshold = 0.52f;
        oxygenBreather.noOxygenThreshold  = 0.05f;
        oxygenBreather.mouthOffset        = new Vector2f(0.25f, 0.7f);
        oxygenBreather.minCO2ToEmit       = 0.02f;
        oxygenBreather.breathableCells    = new CellOffset[6]
        {
            new CellOffset(0, 0),
            new CellOffset(0, 1),
            new CellOffset(1, 1),
            new CellOffset(-1, 1),
            new CellOffset(1, 0),
            new CellOffset(-1, 0)
        };
        gameObject.AddOrGet <WarmBlooded>();
        gameObject.AddOrGet <MinionIdentity>();
        GridVisibility gridVisibility = gameObject.AddOrGet <GridVisibility>();

        gridVisibility.radius      = 30f;
        gridVisibility.innerRadius = 20f;
        gameObject.AddOrGet <MiningSounds>();
        gameObject.AddOrGet <SaveLoadRoot>();
        gameObject.AddOrGet <AntiCluster>();
        Navigator navigator = gameObject.AddOrGet <Navigator>();

        navigator.NavGridName    = "MinionNavGrid";
        navigator.CurrentNavType = NavType.Floor;
        KBatchedAnimController kBatchedAnimController = gameObject.AddOrGet <KBatchedAnimController>();

        kBatchedAnimController.isMovable  = true;
        kBatchedAnimController.sceneLayer = Grid.SceneLayer.Move;
        kBatchedAnimController.AnimFiles  = new KAnimFile[8]
        {
            Assets.GetAnim("body_comp_default_kanim"),
            Assets.GetAnim("anim_construction_default_kanim"),
            Assets.GetAnim("anim_idles_default_kanim"),
            Assets.GetAnim("anim_loco_firepole_kanim"),
            Assets.GetAnim("anim_loco_new_kanim"),
            Assets.GetAnim("anim_loco_tube_kanim"),
            Assets.GetAnim("anim_construction_firepole_kanim"),
            Assets.GetAnim("anim_construction_jetsuit_kanim")
        };
        KBoxCollider2D kBoxCollider2D = gameObject.AddOrGet <KBoxCollider2D>();

        kBoxCollider2D.offset = new Vector2(0f, 0.8f);
        kBoxCollider2D.size   = new Vector2(1f, 1.5f);
        SnapOn snapOn = gameObject.AddOrGet <SnapOn>();

        snapOn.snapPoints = new List <SnapOn.SnapPoint>(new SnapOn.SnapPoint[17]
        {
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"dig",
                buildFile      = Assets.GetAnim("excavator_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"build",
                buildFile      = Assets.GetAnim("constructor_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"fetchliquid",
                buildFile      = Assets.GetAnim("water_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"paint",
                buildFile      = Assets.GetAnim("painting_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"harvest",
                buildFile      = Assets.GetAnim("plant_harvester_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"capture",
                buildFile      = Assets.GetAnim("net_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"attack",
                buildFile      = Assets.GetAnim("attack_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"pickup",
                buildFile      = Assets.GetAnim("pickupdrop_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"store",
                buildFile      = Assets.GetAnim("pickupdrop_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"disinfect",
                buildFile      = Assets.GetAnim("plant_spray_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"tend",
                buildFile      = Assets.GetAnim("plant_harvester_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "carry",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = null,
                overrideSymbol = (HashedString)"snapTo_chest"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "build",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = null,
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "remote",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = null,
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "snapTo_neck",
                automatic      = false,
                context        = (HashedString)string.Empty,
                buildFile      = Assets.GetAnim("helm_oxygen_kanim"),
                overrideSymbol = (HashedString)"snapTo_neck"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"powertinker",
                buildFile      = Assets.GetAnim("electrician_gun_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            },
            new SnapOn.SnapPoint
            {
                pointName      = "dig",
                automatic      = false,
                context        = (HashedString)"specialistdig",
                buildFile      = Assets.GetAnim("excavator_kanim"),
                overrideSymbol = (HashedString)"snapTo_rgtHand"
            }
        });
        gameObject.AddOrGet <Effects>();
        gameObject.AddOrGet <Traits>();
        gameObject.AddOrGet <AttributeLevels>();
        gameObject.AddOrGet <AttributeConverters>();
        PrimaryElement primaryElement = gameObject.AddOrGet <PrimaryElement>();

        primaryElement.InternalTemperature = 310.15f;
        primaryElement.MassPerUnit         = 30f;
        primaryElement.ElementID           = SimHashes.Creature;
        gameObject.AddOrGet <ChoreProvider>();
        gameObject.AddOrGetDef <DebugGoToMonitor.Def>();
        gameObject.AddOrGetDef <SpeechMonitor.Def>();
        gameObject.AddOrGetDef <BlinkMonitor.Def>();
        gameObject.AddOrGetDef <ConversationMonitor.Def>();
        gameObject.AddOrGet <Sensors>();
        gameObject.AddOrGet <Chattable>();
        gameObject.AddOrGet <FaceGraph>();
        gameObject.AddOrGet <Accessorizer>();
        gameObject.AddOrGet <Schedulable>();
        LoopingSounds loopingSounds = gameObject.AddOrGet <LoopingSounds>();

        loopingSounds.updatePosition = true;
        gameObject.AddOrGet <AnimEventHandler>();
        FactionAlignment factionAlignment = gameObject.AddOrGet <FactionAlignment>();

        factionAlignment.Alignment = FactionManager.FactionID.Duplicant;
        gameObject.AddOrGet <Weapon>();
        gameObject.AddOrGet <RangedAttackable>();
        gameObject.AddOrGet <CharacterOverlay>();
        OccupyArea occupyArea = gameObject.AddOrGet <OccupyArea>();

        occupyArea.objectLayers         = new ObjectLayer[1];
        occupyArea.ApplyToCells         = false;
        occupyArea.OccupiedCellsOffsets = new CellOffset[2]
        {
            new CellOffset(0, 0),
            new CellOffset(0, 1)
        };
        gameObject.AddOrGet <Pickupable>();
        CreatureSimTemperatureTransfer creatureSimTemperatureTransfer = gameObject.AddOrGet <CreatureSimTemperatureTransfer>();

        creatureSimTemperatureTransfer.SurfaceArea = 10f;
        creatureSimTemperatureTransfer.Thickness   = 0.01f;
        gameObject.AddOrGet <SicknessTrigger>();
        gameObject.AddOrGet <ClothingWearer>();
        gameObject.AddOrGet <SuitEquipper>();
        DecorProvider decorProvider = gameObject.AddOrGet <DecorProvider>();

        decorProvider.baseRadius = 3f;
        decorProvider.isMovable  = true;
        gameObject.AddOrGet <ConsumableConsumer>();
        gameObject.AddOrGet <NoiseListener>();
        gameObject.AddOrGet <MinionResume>();
        DuplicantNoiseLevels.SetupNoiseLevels();
        SetupLaserEffects(gameObject);
        SymbolOverrideController symbolOverrideController = SymbolOverrideControllerUtil.AddToPrefab(gameObject);

        symbolOverrideController.applySymbolOverridesEveryFrame = true;
        ConfigureSymbols(gameObject);
        return(gameObject);
    }