예제 #1
0
 public void NotifyPowerSourceMaxPowerChangedHandlers(TileEntityPowerSource te, int oldValue, int newValue)
 {
     if (OnPowerSourceMaxOutputChanged != null)
     {
         OnPowerSourceMaxOutputChanged(te, oldValue, newValue);
     }
 }
예제 #2
0
 public void NotifyPowerSourceTurnedOffHandlers(TileEntityPowerSource te)
 {
     if (OnPowerSourceTurnedOff != null)
     {
         OnPowerSourceTurnedOff(te);
     }
 }
예제 #3
0
 public void NotifyPowerSourceCurrentFuelChangedHandlers(TileEntityPowerSource te, int oldValue, int newValue)
 {
     if (OnPowerSourceFuelChanged != null)
     {
         OnPowerSourceFuelChanged(te, oldValue, newValue);
     }
 }
    void Update()
    {
        TileEntityPowerSource tileEntityPowerSource = (TileEntityPowerSource)GameManager.Instance.World.GetTileEntity(cIdx, blockPos);

        if (tileEntityPowerSource != null && renderers != null)
        {
            curIsOn = tileEntityPowerSource.IsOn;
            if (curIsOn != isOn)
            {
                isOn = curIsOn;
                if (isOn)
                {
                    //Audio.Manager.BroadcastPlay(blockPos.ToVector3(), soundRepeat);
                    soundRepeatOffsetStart = Time.time;
                    foreach (Renderer rend in renderers)
                    {
                        if (rend.material.name.Contains("Mod4Lightcone"))
                        {
                            rend.material.SetColor("_Color", new Color(0, 0.67f, 1));
                        }
                        else
                        {
                            rend.material.EnableKeyword("_EMISSION");
                            rend.material.SetColor("_EmissionColor", new Color(1, 1, 1));
                        }
                    }
                }
                else
                {
                    Audio.Manager.BroadcastStop(blockPos.ToVector3(), soundRepeat);
                    foreach (Renderer rend in renderers)
                    {
                        if (rend.material.name.Contains("Mod4Lightcone"))
                        {
                            rend.material.SetColor("_Color", new Color(0, 0, 0));
                        }
                        else
                        {
                            rend.material.EnableKeyword("_EMISSION");
                            rend.material.SetColor("_EmissionColor", new Color(0, 0, 0));
                        }
                    }
                }
            }

            if (isOn)
            {
                if (soundRepeatOffsetStart != -1 && Time.time - soundRepeatOffsetStart > 0.85f)
                {
                    Audio.Manager.BroadcastPlay(blockPos.ToVector3(), soundRepeat);
                    soundRepeatOffsetStart = -1;
                }
            }
        }
    }
예제 #5
0
    public override TileEntityPowerSource CreateTileEntity(Chunk chunk)
    {
        if (this.slotItem == null)
        {
            this.slotItem = ItemClass.GetItemClass(this.SlotItemName, false);
        }
        TileEntityPowerSource entityPowerSource = new TileEntityPowerSource(chunk);

        entityPowerSource.PowerItemType = (PowerItem.PowerItemTypes) 12;
        entityPowerSource.SlotItem      = this.slotItem;
        //entityPowerSource.PowerItem = new WindmillPowerItem();
        return(entityPowerSource);
    }
예제 #6
0
    IEnumerator CheckAnimation(Animator animator, int _cIdx, Vector3i _blockPos, float MinSpeed, float MaxSpeed, float WattsPerMph)
    {
        float lastChange = float.MinValue;
        var   ret        = new WaitForSeconds(10);

        var missingCount = 0;

        //Debug.Log("Starting coroutine for Windmill " + _blockPos);
        while (true)
        {
            if (GameManager.Instance == null || GameManager.Instance.World == null)
            {
                //Debug.Log("Windmill world not active");
                yield break;
            }
            else
            {
                TileEntityPowerSource tileEntity = GameManager.Instance.World.GetTileEntity(_cIdx, _blockPos) as TileEntityPowerSource;
                if (tileEntity == null)
                {
                    Log.Out("Tile Entity missing for windmill count" + missingCount);
                    if (++missingCount > 5)
                    {
                        break;
                    }
                }
                else if (animator != null)
                {
                    var CurrentWindSpeed = (float)tileEntity.MaxOutput / WattsPerMph;
                    var speed            = CurrentWindSpeed < MinSpeed ? 0 : CurrentWindSpeed / MaxSpeed;
                    var change           = Mathf.Abs(speed - lastChange);
                    if (change > 0.1f || CurrentWindSpeed == 0)
                    {
                        lastChange = speed;
                        GameManager.Instance.StartCoroutine(ChangeSpeed(animator, speed));
                    }
                }
            }

            yield return(ret);
        }

        //Debug.Log("Ending coroutine for Windmill " + _blockPos);
    }
    public override void OnBlockEntityTransformBeforeActivated(WorldBase _world, Vector3i _blockPos, int _cIdx, BlockValue _blockValue, BlockEntityData _ebcd)
    {
        this.shape.OnBlockEntityTransformBeforeActivated(_world, _blockPos, _cIdx, _blockValue, _ebcd);
        DebugMsg("OnBlockEntityTransformBeforeActivated");
        try
        {
            if (_ebcd != null && _ebcd.bHasTransform)
            {
                GameObject gameObject = _ebcd.transform.gameObject;
                PerpetualMotionGeneratorControl PMGControlScript = gameObject.GetComponent <PerpetualMotionGeneratorControl>();
                if (PMGControlScript == null)
                {
                    PMGControlScript = gameObject.AddComponent <PerpetualMotionGeneratorControl>();
                }
                PMGControlScript.enabled     = true;
                PMGControlScript.cIdx        = _cIdx;
                PMGControlScript.blockPos    = _blockPos;
                PMGControlScript.soundRepeat = soundRepeat;
            }
            else
            {
                DebugMsg("ERROR: _ebcd null (OnBlockEntityTransformBeforeActivated)");
            }
        }
        catch (Exception ex)
        {
            DebugMsg("Error Message: " + ex.ToString());
        }

        // Offset wire so that it's at the base of the Healing Pod
        TileEntityPowerSource tileEntityPowerSource = (TileEntityPowerSource)_world.GetTileEntity(_cIdx, _blockPos);

        if (tileEntityPowerSource != null)
        {
            tileEntityPowerSource.WireOffset = new Vector3(0.25f, 0.4f, 0);
        }
    }
 public BCMTileEntityPowerSource(Vector3i pos, TileEntityPowerSource te) : base(pos, te)
 {
     //var powerItem = te.GetPowerItem();
     //todo
 }
예제 #9
0
        public static bool CheckWorkstationForPower(TileEntity myTileEntity)
        {
            AdvLogging.DisplayLog(AdvFeatureClass, "Does Workstation have access to Fuel?");
            bool blNeedsPower = false;

            // Read the block properties whenever we check, since we don't really persists whether or not we need power.
            BlockValue block = GameManager.Instance.World.GetBlock(myTileEntity.ToWorldPos());
            Block block2 = Block.list[block.type];
            blNeedsPower = false;
            if (block2.Properties.Values.ContainsKey("RequirePower"))
                blNeedsPower = StringParsers.ParseBool(block2.Properties.Values["RequirePower"], 0, -1, true);

            AdvLogging.DisplayLog(AdvFeatureClass, "Require Power? : " + blNeedsPower);

            // Doesn't need any power, so don't check.
            if (blNeedsPower == false)
                return true;

            AdvLogging.DisplayLog(AdvFeatureClass, "Workstation requires power. Checking near by tile entities.");

            // Check the nearby chunks for Power source tile entities, and check if they are on.
            Vector3i blockPosition = myTileEntity.ToWorldPos();
            World world = GameManager.Instance.World;
            int num = World.toChunkXZ(blockPosition.x);
            int num2 = World.toChunkXZ(blockPosition.z);
            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    Chunk chunk = (Chunk)world.GetChunkSync(num + j, num2 + i);
                    if (chunk != null)
                    {
                        DictionaryList<Vector3i, TileEntity> tileEntities = chunk.GetTileEntities();
                        for (int k = 0; k < tileEntities.list.Count; k++)
                        {
                            AdvLogging.DisplayLog(AdvFeatureClass, "\tDetected Tile Entity: " + tileEntities.list[k].ToString());
                            TileEntityPowerSource tileEntity = tileEntities.list[k] as TileEntityPowerSource;
                            if (tileEntity != null)
                            {
                                if (tileEntity.IsActive(world))
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tEntity is Avtive " + tileEntities.list[k].ToString());
                                if (tileEntity.IsOn)
                                {
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tTile Entity is On: " + tileEntities.list[k].ToString());
                                    float distanceSq = (blockPosition.ToVector3() - tileEntity.ToWorldPos().ToVector3()).sqrMagnitude;
                                    if (distanceSq <= 20 * 20)
                                    {
                                        AdvLogging.DisplayLog(AdvFeatureClass, myTileEntity.ToString() + " Found Power Source as Fuel with " + tileEntity.ToString());
                                        //myTileEntity.HasPowerSDX = true;
                                        return true;
                                    }
                                }
                                else
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tTile Entity is off: " + tileEntities.list[k].ToString());
                            }
                        }
                    }
                }
            }
            return false;
        }