예제 #1
0
    public float SupportValue(StabilityEntity ignoreEntity = null)
    {
        if (this.grounded || this.supports == null)
        {
            return(1f);
        }
        if (Object.op_Equality((Object)ignoreEntity, (Object)null))
        {
            ignoreEntity = this;
        }
        float num1 = 0.0f;

        for (int index = 0; index < this.supports.Count; ++index)
        {
            StabilityEntity.Support support         = this.supports[index];
            StabilityEntity         stabilityEntity = support.SupportEntity(ignoreEntity);
            if (!Object.op_Equality((Object)stabilityEntity, (Object)null))
            {
                float num2 = stabilityEntity.CachedSupportValue(ignoreEntity);
                if ((double)num2 != 0.0)
                {
                    num1 += num2 * support.factor;
                }
            }
        }
        return(Mathf.Clamp01(num1));
    }
    public float CachedSupportValue(StabilityEntity ignoreEntity = null)
    {
        if (this.grounded)
        {
            return(1f);
        }
        if (this.supports == null)
        {
            return(1f);
        }
        if (ignoreEntity == null)
        {
            ignoreEntity = this;
        }
        float single = 0f;

        for (int i = 0; i < this.supports.Count; i++)
        {
            StabilityEntity.Support item            = this.supports[i];
            StabilityEntity         stabilityEntity = item.SupportEntity(ignoreEntity);
            if (stabilityEntity != null)
            {
                float single1 = stabilityEntity.cachedStability;
                if (single1 != 0f)
                {
                    single = single + single1 * item.factor;
                }
            }
        }
        return(Mathf.Clamp01(single));
    }
    public int CachedDistanceFromGround(StabilityEntity ignoreEntity = null)
    {
        if (this.grounded)
        {
            return(1);
        }
        if (this.supports == null)
        {
            return(1);
        }
        if (ignoreEntity == null)
        {
            ignoreEntity = this;
        }
        int num = 2147483647;

        for (int i = 0; i < this.supports.Count; i++)
        {
            StabilityEntity stabilityEntity = this.supports[i].SupportEntity(ignoreEntity);
            if (stabilityEntity != null)
            {
                int num1 = stabilityEntity.cachedDistanceFromGround;
                if (num1 != 2147483647)
                {
                    num = Mathf.Min(num, num1 + 1);
                }
            }
        }
        return(num);
    }
예제 #4
0
    public int DistanceFromGround(StabilityEntity ignoreEntity = null)
    {
        if (this.grounded || this.supports == null)
        {
            return(1);
        }
        if (Object.op_Equality((Object)ignoreEntity, (Object)null))
        {
            ignoreEntity = this;
        }
        int num1 = int.MaxValue;

        for (int index = 0; index < this.supports.Count; ++index)
        {
            StabilityEntity stabilityEntity = this.supports[index].SupportEntity(ignoreEntity);
            if (!Object.op_Equality((Object)stabilityEntity, (Object)null))
            {
                int num2 = stabilityEntity.CachedDistanceFromGround(ignoreEntity);
                if (num2 != int.MaxValue)
                {
                    num1 = Mathf.Min(num1, num2 + 1);
                }
            }
        }
        return(num1);
    }
        public StabilityEntity SupportEntity(StabilityEntity ignoreEntity = null)
        {
            StabilityEntity stabilityEntity = null;

            for (int i = 0; i < this.link.connections.Count; i++)
            {
                StabilityEntity item = this.link.connections[i].owner as StabilityEntity;
                if (!(item == null) && !(item == this.parent) && !(item == ignoreEntity) && !item.isClient && !item.IsDestroyed && (stabilityEntity == null || item.cachedDistanceFromGround < stabilityEntity.cachedDistanceFromGround))
                {
                    stabilityEntity = item;
                }
            }
            return(stabilityEntity);
        }
예제 #6
0
        public StabilityEntity SupportEntity(StabilityEntity ignoreEntity = null)
        {
            StabilityEntity stabilityEntity = (StabilityEntity)null;

            for (int index = 0; index < this.link.connections.Count; ++index)
            {
                StabilityEntity owner = this.link.connections[index].owner as StabilityEntity;
                if (!Object.op_Equality((Object)owner, (Object)null) && !Object.op_Equality((Object)owner, (Object)this.parent) && (!Object.op_Equality((Object)owner, (Object)ignoreEntity) && !owner.isClient) && (!owner.IsDestroyed && (Object.op_Equality((Object)stabilityEntity, (Object)null) || owner.cachedDistanceFromGround < stabilityEntity.cachedDistanceFromGround)))
                {
                    stabilityEntity = owner;
                }
            }
            return(stabilityEntity);
        }
예제 #7
0
            private void Awake()
            {
                nextTime = Time.time + 0.5f;
                target   = gameObject.GetComponent <BaseEntity>();
                stab     = target?.GetComponent <StabilityEntity>();

                plugin.NextTick(() =>
                {
                    if (!originPlayer)
                    {
                        return;
                    }
                    if (plugin.permission.UserHasPermission(originPlayer.UserIDString, permissionNameRESTRICTED))
                    {
                        isRestricted = true;
                    }
                });
            }
    public void UpdateConnectedEntities()
    {
        List <EntityLink> entityLinks = base.GetEntityLinks(true);

        for (int i = 0; i < entityLinks.Count; i++)
        {
            EntityLink item = entityLinks[i];
            if (item.IsFemale())
            {
                for (int j = 0; j < item.connections.Count; j++)
                {
                    StabilityEntity stabilityEntity = item.connections[j].owner as StabilityEntity;
                    if (!(stabilityEntity == null) && !stabilityEntity.isClient && !stabilityEntity.IsDestroyed)
                    {
                        stabilityEntity.UpdateStability();
                    }
                }
            }
        }
    }
예제 #9
0
    public void UpdateConnectedEntities()
    {
        List <EntityLink> entityLinks = this.GetEntityLinks(true);

        for (int index1 = 0; index1 < entityLinks.Count; ++index1)
        {
            EntityLink entityLink = entityLinks[index1];
            if (entityLink.IsFemale())
            {
                for (int index2 = 0; index2 < entityLink.connections.Count; ++index2)
                {
                    StabilityEntity owner = entityLink.connections[index2].owner as StabilityEntity;
                    if (!Object.op_Equality((Object)owner, (Object)null) && !owner.isClient && !owner.IsDestroyed)
                    {
                        owner.UpdateStability();
                    }
                }
            }
        }
    }
예제 #10
0
    private static bool TestPlacingThroughWall(ref Placement placement, Transform transform, Construction common, Target target)
    {
        Vector3    vector = placement.position - target.ray.origin;
        RaycastHit hitInfo;

        if (!Physics.Raycast(target.ray.origin, vector.normalized, out hitInfo, vector.magnitude, 2097152))
        {
            return(true);
        }
        StabilityEntity stabilityEntity = RaycastHitEx.GetEntity(hitInfo) as StabilityEntity;

        if (stabilityEntity != null && target.entity == stabilityEntity)
        {
            return(true);
        }
        if (vector.magnitude - hitInfo.distance < 0.2f)
        {
            return(true);
        }
        lastPlacementError = "object in placement path";
        transform.SetPositionAndRotation(hitInfo.point, placement.rotation);
        return(false);
    }
예제 #11
0
    private static bool TestPlacingThroughWall(
        ref Construction.Placement placement,
        Transform transform,
        Construction common,
        Construction.Target target)
    {
        Vector3    vector3 = Vector3.op_Subtraction(placement.position, ((Ray) ref target.ray).get_origin());
        RaycastHit hit;

        if (!Physics.Raycast(((Ray) ref target.ray).get_origin(), ((Vector3) ref vector3).get_normalized(), ref hit, ((Vector3) ref vector3).get_magnitude(), 2097152))
        {
            return(true);
        }
        StabilityEntity entity = hit.GetEntity() as StabilityEntity;

        if (Object.op_Inequality((Object)entity, (Object)null) && Object.op_Equality((Object)target.entity, (Object)entity) || (double)((Vector3) ref vector3).get_magnitude() - (double)((RaycastHit) ref hit).get_distance() < 0.200000002980232)
        {
            return(true);
        }
        Construction.lastPlacementError = "object in placement path";
        transform.set_position(((RaycastHit) ref hit).get_point());
        transform.set_rotation(placement.rotation);
        return(false);
    }
예제 #12
0
    private static bool TestPlacingThroughWall(ref Construction.Placement placement, Transform transform, Construction common, Construction.Target target)
    {
        RaycastHit raycastHit;
        Vector3    vector3 = placement.position - target.ray.origin;

        if (!Physics.Raycast(target.ray.origin, vector3.normalized, out raycastHit, vector3.magnitude, 2097152))
        {
            return(true);
        }
        StabilityEntity entity = raycastHit.GetEntity() as StabilityEntity;

        if (entity != null && target.entity == entity)
        {
            return(true);
        }
        if (vector3.magnitude - raycastHit.distance < 0.2f)
        {
            return(true);
        }
        Construction.lastPlacementError = "object in placement path";
        transform.position = raycastHit.point;
        transform.rotation = placement.rotation;
        return(false);
    }
 public Support(StabilityEntity parent, EntityLink link, float factor)
 {
     this.parent = parent;
     this.link   = link;
     this.factor = factor;
 }
예제 #14
0
    public GameObject DoPlacement(Construction.Target placement, Construction component)
    {
        BasePlayer ownerPlayer = base.GetOwnerPlayer();

        if (!ownerPlayer)
        {
            return(null);
        }
        BaseEntity baseEntity = component.CreateConstruction(placement, true);

        if (!baseEntity)
        {
            return(null);
        }
        float single    = 1f;
        float single1   = 0f;
        Item  ownerItem = base.GetOwnerItem();

        if (ownerItem != null)
        {
            baseEntity.skinID = ownerItem.skin;
            if (ownerItem.hasCondition)
            {
                single = ownerItem.conditionNormalized;
            }
        }
        baseEntity.gameObject.AwakeFromInstantiate();
        BuildingBlock buildingBlock = baseEntity as BuildingBlock;

        if (buildingBlock)
        {
            buildingBlock.blockDefinition = PrefabAttribute.server.Find <Construction>(buildingBlock.prefabID);
            if (!buildingBlock.blockDefinition)
            {
                Debug.LogError("Placing a building block that has no block definition!");
                return(null);
            }
            buildingBlock.SetGrade(buildingBlock.blockDefinition.defaultGrade.gradeBase.type);
            single1 = buildingBlock.currentGrade.maxHealth;
        }
        BaseCombatEntity baseCombatEntity = baseEntity as BaseCombatEntity;

        if (baseCombatEntity)
        {
            single1 = (buildingBlock != null ? buildingBlock.currentGrade.maxHealth : baseCombatEntity.startHealth);
            baseCombatEntity.ResetLifeStateOnSpawn = false;
            baseCombatEntity.InitializeHealth(single1 * single, single1);
        }
        baseEntity.gameObject.SendMessage("SetDeployedBy", ownerPlayer, SendMessageOptions.DontRequireReceiver);
        baseEntity.OwnerID = ownerPlayer.userID;
        baseEntity.Spawn();
        if (buildingBlock)
        {
            Effect.server.Run("assets/bundled/prefabs/fx/build/frame_place.prefab", baseEntity, 0, Vector3.zero, Vector3.zero, null, false);
        }
        StabilityEntity stabilityEntity = baseEntity as StabilityEntity;

        if (stabilityEntity)
        {
            stabilityEntity.UpdateSurroundingEntities();
        }
        return(baseEntity.gameObject);
    }
예제 #15
0
    public GameObject DoPlacement(Construction.Target placement, Construction component)
    {
        BasePlayer ownerPlayer = this.GetOwnerPlayer();

        if (!Object.op_Implicit((Object)ownerPlayer))
        {
            return((GameObject)null);
        }
        BaseEntity construction = component.CreateConstruction(placement, true);

        if (!Object.op_Implicit((Object)construction))
        {
            return((GameObject)null);
        }
        float num1      = 1f;
        float num2      = 0.0f;
        Item  ownerItem = this.GetOwnerItem();

        if (ownerItem != null)
        {
            construction.skinID = ownerItem.skin;
            if (ownerItem.hasCondition)
            {
                num1 = ownerItem.conditionNormalized;
            }
        }
        ((Component)construction).get_gameObject().AwakeFromInstantiate();
        BuildingBlock buildingBlock = construction as BuildingBlock;

        if (Object.op_Implicit((Object)buildingBlock))
        {
            buildingBlock.blockDefinition = PrefabAttribute.server.Find <Construction>(buildingBlock.prefabID);
            if (!(bool)((PrefabAttribute)buildingBlock.blockDefinition))
            {
                Debug.LogError((object)"Placing a building block that has no block definition!");
                return((GameObject)null);
            }
            buildingBlock.SetGrade(buildingBlock.blockDefinition.defaultGrade.gradeBase.type);
            num2 = buildingBlock.currentGrade.maxHealth;
        }
        BaseCombatEntity baseCombatEntity = construction as BaseCombatEntity;

        if (Object.op_Implicit((Object)baseCombatEntity))
        {
            float newmax = Object.op_Inequality((Object)buildingBlock, (Object)null) ? buildingBlock.currentGrade.maxHealth : baseCombatEntity.startHealth;
            baseCombatEntity.ResetLifeStateOnSpawn = false;
            baseCombatEntity.InitializeHealth(newmax * num1, newmax);
        }
        ((Component)construction).get_gameObject().SendMessage("SetDeployedBy", (object)ownerPlayer, (SendMessageOptions)1);
        construction.OwnerID = ownerPlayer.userID;
        construction.Spawn();
        if (Object.op_Implicit((Object)buildingBlock))
        {
            Effect.server.Run("assets/bundled/prefabs/fx/build/frame_place.prefab", construction, 0U, Vector3.get_zero(), Vector3.get_zero(), (Connection)null, false);
        }
        StabilityEntity stabilityEntity = construction as StabilityEntity;

        if (Object.op_Implicit((Object)stabilityEntity))
        {
            stabilityEntity.UpdateSurroundingEntities();
        }
        return(((Component)construction).get_gameObject());
    }