Example #1
0
        public override bool HasJobOnThing(Pawn pawn, Thing t)
        {
            Building_RepairStation rps      = t as Building_RepairStation;
            IRepairable            repairee = pawn as IRepairable;

            return(rps != null && repairee != null && rps.IsAvailable(repairee) && pawn.CanReserveAndReach(rps, PathEndMode, Danger.Some, 1));
        }
Example #2
0
    IEnumerator Repair(IRepairable active)
    {
        float timeToRepair = 3f;         //in seconds

        while (timeToRepair > 0f)
        {
            timeToRepair -= Time.deltaTime;
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, ActivationDistance, LayMask))
            {
                if (hit.collider.GetComponent <IRepairable> () == null)
                {
                    StopAllCoroutines();
                }
            }
            else
            {
                StopAllCoroutines();
            }
            if (ActivationToolTipText != null)
            {
                ActivationToolTipText.text = timeToRepair.ToString();
            }
            yield return(null);
        }
        active.Repair();
        float f = .35f;

        while (f > 0f)
        {
            ActivationToolTipText.text = "Repaired " + active.GetName();
            yield return(null);
        }
    }
Example #3
0
    private IEnumerator CauseRandomFailure()
    {
        int         tries  = 0;
        IRepairable victim = null;

        while (victim == null)
        {
            victim = registeredRepairables[UnityEngine.Random.Range(0, registeredRepairables.Count)];

            if (!victim.CanMalfunction)
            {
                victim = null;
            }
            else if (tries > 10) //include a failsafe for 10 non-victims in a row
            {
                break;
            }

            tries++;
        }

        if (victim == null)
        {
            //give up
        }
        else
        {
            FailureType fail = GetRandomFailType(victim);

            yield return(CauseFailure(victim, fail));
        }
    }
Example #4
0
 internal void Deregister(IRepairable repairable)
 {
     if (registeredRepairables.Contains(repairable))
     {
         registeredRepairables.Remove(repairable);
     }
 }
Example #5
0
    internal void FinishRepair(IRepairable repaired)
    {
        repaired.FaultedPercentage = 0f;
        Gremlind fixing = gremlindMap[repaired];

        gremlindMap.Remove(repaired);
        fixing.Effect.SetParent(null);
        fixing.Effect.gameObject.SetActive(false);
        repaired.transform.root.tag = fixing.PreviousTag;
        particleSystemPool[fixing.FailType].Add(fixing.Effect);
        if (fixing.FailType == FailureType.Electrical)
        {
            FlowManager.Instance.PowerGrids.HandleElectricalFailureChange(repaired, false);
        }
        else if (fixing.FailType == FailureType.Pressure && repaired is GasStorage)
        {
            (repaired as GasStorage).ToggleLeak(false);
        }
        else if (fixing.FailType == FailureType.HabitatPressure && repaired is IHabitatModule)
        {
            (repaired as IHabitatModule).LinkedHabitat.ToggleOxygenLeak(false);
        }
        Game.Current.Player.GremlinChastised = true;
        GuiBridge.Instance.ShowNews(NewsSource.MalfunctionRepaired);
        PlayerInput.Instance.ToggleRepairMode(false);
    }
 public bool IsAvailable(IRepairable p)
 {
     if (Power != null)
     {
         return(Power.PowerOn && CanUse(p));
     }
     return(CanUse(p));
 }
Example #7
0
    private IEnumerator CauseFailure(IRepairable victim, FailureType fail)
    {
        Transform effect = GetFailureParticleSystemFromPool(fail);
        AudioClip failClip = null, announcementClip = null;

        gremlindMap.Add(victim, new Gremlind()
        {
            FailType    = fail,
            Effect      = effect,
            PreviousTag = victim.transform.root.tag
        });

        victim.transform.root.tag = GremlindTag;

        //if we've loaded a pre-existing fault percentage, don't undo the repair
        if (victim.FaultedPercentage == 0f)
        {
            victim.FaultedPercentage = 1f;
        }

        if (fail == FailureType.Electrical)
        {
            effect.SetParent(victim.FailureEffectAnchors.Electrical);
            //alert the powergrid script
            FlowManager.Instance.PowerGrids.HandleElectricalFailureChange(victim, true);
            announcementClip = this.ElectricalFailureComputerTalk;
            failClip         = this.ElectricalFailureSound;
        }
        else if (fail == FailureType.Pressure && victim is GasStorage)
        {
            effect.SetParent(victim.FailureEffectAnchors.Pressure);
            announcementClip = this.PressureFailureComputerTalk;
            failClip         = this.PressureFailureSound;
            (victim as GasStorage).ToggleLeak(true);
        }
        else if (fail == FailureType.HabitatPressure && victim is IHabitatModule)
        {
            effect.SetParent(victim.FailureEffectAnchors.HabitatPressure);
            announcementClip = this.PressureFailureComputerTalk;
            failClip         = this.PressureFailureSound;
            (victim as IHabitatModule).LinkedHabitat.ToggleOxygenLeak(true);
        }

        effect.transform.localPosition = Vector3.zero;
        effect.transform.localRotation = Quaternion.identity;

        GremlinAudio.transform.position = effect.transform.position;

        SunOrbit.Instance.CheckEmergencyReset();
        GremlinAudio.PlayOneShot(failClip);

        yield return(new WaitForSeconds(failClip.length));

        SunOrbit.Instance.CheckEmergencyReset();
        GuiBridge.Instance.ComputerAudioSource.PlayOneShot(announcementClip);
        GuiBridge.Instance.ShowNews(NewsSource.GetFailureNews(victim, fail));
        PlayerInput.Instance.ToggleRepairMode(true);
    }
Example #8
0
    internal void EffectRepair(IRepairable repairable)
    {
        repairable.FaultedPercentage -= RepairPercentagePerSecond * Time.deltaTime;

        if (repairable.FaultedPercentage <= 0f)
        {
            FinishRepair(repairable);
        }
    }
Example #9
0
        public void RepairPartWhichHasNotBeenPreviouslyAddedThrowsInvalidOperationException(
            string deviceTypeString,
            string deviceMake)
        {
            Type        deviceType     = this.partAssembly.GetTypes().First(x => x.Name == deviceTypeString);
            IRepairable deviceInstance = (IRepairable)Activator.CreateInstance(deviceType, deviceMake);

            Assert.Throws <InvalidOperationException>(() => deviceInstance.RepairPart("CPU"));
        }
Example #10
0
        public void RepairPartWithNullOrEmptyNameThrowsArgumentException(
            string deviceTypeString,
            string deviceMake,
            string partName)
        {
            Type        deviceType     = this.partAssembly.GetTypes().First(x => x.Name == deviceTypeString);
            IRepairable deviceInstance = (IRepairable)Activator.CreateInstance(deviceType, deviceMake);

            Assert.Throws <ArgumentException>(() => deviceInstance.RepairPart(partName));
        }
Example #11
0
        public RepairViewModel(ILoot loot, bool is_info) : base(loot, is_info)
        {
            RepairCommand = new Command(Repair);

            Player     = Player.Instance;
            repairable = loot.Item as IRepairable;

            Repairs = new ObservableCollection <CraftItem>();
            GetRepairs();
        }
Example #12
0
        public void DeviceConstructorWorksCorrectly(string deviceTypeString, string deviceMake)
        {
            Type deviceType = this.partAssembly.GetTypes().First(x => x.Name == deviceTypeString);

            IRepairable deviceInstance = (IRepairable)Activator.CreateInstance(deviceType, deviceMake);

            Assert.AreEqual(deviceMake, deviceInstance.Make);
            Assert.IsNotNull(deviceInstance.Parts);
            Assert.AreEqual(0, deviceInstance.Parts.Count);
        }
Example #13
0
    internal void EffectRepair(IRepairable repairable)
    {
        repairable.FaultedPercentage -= RepairPercentagePerSecond * Time.deltaTime;

        if (repairable.FaultedPercentage <= 0f)
        {
            FinishRepair(repairable);
        }

        Game.Current.Score.RepairsEffected++;
    }
Example #14
0
    private static string GetThingName(IRepairable victim)
    {
        if (victim is ModuleGameplay)
            return (victim as ModuleGameplay).GetModuleType().ToString();
        else if (victim is IceDrill)
            return "Ice Drill";
        else if (victim is PowerCube)
            return "Power Cube";

        return "";
    }
Example #15
0
        public void AddWrongPartTypeThrowsInvalidOperationException(
            string deviceTypeString,
            string deviceMake,
            string partTypeString)
        {
            Type        deviceType     = this.partAssembly.GetTypes().First(x => x.Name == deviceTypeString);
            IRepairable deviceInstance = (IRepairable)Activator.CreateInstance(deviceType, deviceMake);
            Type        partType       = this.partAssembly.GetTypes().First(x => x.Name == partTypeString);
            IPart       part           = (IPart)Activator.CreateInstance(partType, "processor", 350.97m, false);

            Assert.Throws <InvalidOperationException>(() => deviceInstance.AddPart(part));
        }
Example #16
0
        public RepairData(IRepairable repairTarget, string repairOptionDescription, double workUnits, bool qualityDependent, Dictionary <string, double> requestedResources,
                          bool useForFullRepair, bool isSelected = false, bool completed = false, float progressRatio = 0)
        {
            this.repairTarget            = repairTarget;
            this.repairOptionDescription = repairOptionDescription;
            this.workUnits          = workUnits;
            this.qualityDependent   = qualityDependent;
            this.requestedResources = requestedResources;
            this.useForFullRepair   = useForFullRepair;

            this.isSelected    = isSelected;
            this.completed     = completed;
            this.progressRatio = progressRatio;
        }
Example #17
0
    internal void Register(IRepairable repairable)
    {
        if (repairable.GetFailureModes().Length > 0)
        {
            registeredRepairables.Add(repairable);

            //should only happen after loading a game
            if (repairable.FaultedPercentage > 0f)
            {
                StopCoroutine(GremlinCoroutine);
#warning bug: may lose the right kind of failure here if supports both electrical and pressure
                CauseFailure(repairable, GetRandomFailType(repairable));
            }
        }
    }
Example #18
0
    public static News GetFailureNews(IRepairable victim, Gremlin.FailureType failType)
    {
        string thingName = GetThingName(victim);

        if (failType == Gremlin.FailureType.Electrical)
        {
            ElectricalFailure.Text = thingName + " Electrical Failure!";
            return ElectricalFailure;
        }
        else
        {
            PressureFailure.Text = thingName + " Pressure Failure!";
            return PressureFailure;
        }
    }
Example #19
0
        public void AddPartFunctionalityWorksCorrectly(string deviceTypeString, string deviceMake, string partTypeString)
        {
            Type         deviceType        = this.partAssembly.GetTypes().First(x => x.Name == deviceTypeString);
            IRepairable  deviceInstance    = (IRepairable)Activator.CreateInstance(deviceType, deviceMake);
            Type         partType          = this.partAssembly.GetTypes().First(x => x.Name == partTypeString);
            IPart        firstPart         = (IPart)Activator.CreateInstance(partType, "processor", 350.97m, false);
            IPart        secondPart        = (IPart)Activator.CreateInstance(partType, "someOtherpart", 31220.97m, true);
            List <IPart> partsListExpected = new List <IPart> {
                firstPart, secondPart
            };

            deviceInstance.AddPart(firstPart);
            deviceInstance.AddPart(secondPart);

            Assert.IsTrue(partsListExpected.SequenceEqual(deviceInstance.Parts));
        }
Example #20
0
        internal void HandleElectricalFailureChange(IRepairable victim, bool faulted)
        {
            if (victim is IPowerConsumer)
            {
                if (faulted)
                {
                    (victim as IPowerConsumer).EmergencyShutdown();
                }
                else
                {
                    (victim as IPowerConsumer).TurnOnPower();
                }
            }

            this.OnElectricalFailureChange(victim);
        }
Example #21
0
        public void RepairPartFunctionalityWorksCorrectly(
            string deviceTypeString,
            string deviceMake,
            string partTypeString)
        {
            Type        deviceType     = this.partAssembly.GetTypes().First(x => x.Name == deviceTypeString);
            IRepairable deviceInstance = (IRepairable)Activator.CreateInstance(deviceType, deviceMake);
            Type        partType       = this.partAssembly.GetTypes().First(x => x.Name == partTypeString);
            IPart       part           = (IPart)Activator.CreateInstance(partType, "processor", 350.97m, true);

            deviceInstance.AddPart(part);

            deviceInstance.RepairPart(part.Name);
            List <IPart> deviceParts = (List <IPart>)deviceInstance.Parts;

            Assert.AreEqual(false, deviceParts[0].IsBroken);
        }
    private static string GetThingName(IRepairable victim)
    {
        if (victim is ModuleGameplay)
        {
            return((victim as ModuleGameplay).GetModuleType().ToString());
        }
        else if (victim is IceDrill)
        {
            return("Ice Drill");
        }
        else if (victim is PowerCube)
        {
            return("Power Cube");
        }

        return("");
    }
Example #23
0
            private void DamageItem(Mobile from, int damageAmount, IRepairable repairable, ref int number)
            {
                damageAmount = Math.Max(damageAmount, 1);

                if (damageAmount >= repairable.HitPoints)
                {
                    number = 500424; // You destroyed the item.
                    from.SendFailureMessage(number);
                    repairable.Delete();
                }
                else
                {
                    number = 500039; // Failed!
                    from.SendFailureMessage("You fail in your repairing attempt and damage the item!");
                    repairable.HitPoints -= damageAmount;
                }
            }
Example #24
0
        internal void OnElectricalFailureChange(IRepairable repairable)
        {
            if (repairable is IPowerConsumer)
            {
                (repairable as IPowerConsumer).RefreshVisualization();
            }

            //batteries don't lose charge, just can't charge/discharge
            //if (victim is IBattery)
            //{
            //    (victim as IBattery).RefreshVisualization();
            //}

            if (repairable is IPowerSupply)
            {
                (repairable as IPowerSupply).RefreshVisualization();
            }
        }
Example #25
0
    // Update is called once per frame
    void Update()
    {
        //		activationRay = new Ray (transform.position, transform.forward);
        RaycastHit hit;

        try{
            if (Physics.Raycast(transform.position, transform.forward, out hit, ActivationDistance, LayMask))
            {
                if (hit.collider.GetComponent <IRepairable> () != null)
                {
                    IRepairable active = hit.collider.GetComponent <IRepairable> ();
                    activego = hit.collider.gameObject;
                    if (Input.GetKeyDown(KeyCode.R) && !active.IsFunctional())
                    {
                        StartCoroutine("Repair", active);
                    }
                    else
                    {
                        if (active.IsFunctional())
                        {
                            ActivationToolTipText.text = active.GetName() + " is fully functional.";
                        }
                        else
                        {
                            ActivationToolTipText.text = "Press R to Repair " + active.GetName();
                        }
                    }
                }
                else
                {
                    ActivationToolTipText.text = emptyString;
                }
            }
            else
            {
                ActivationToolTipText.text = emptyString;
            }
        }
        catch {
            //idc
        }
    }
Example #26
0
    public static Gremlin.FailureType[] GetFailureModes(this IRepairable rep)
    {
        List <Gremlin.FailureType> modes = new List <Gremlin.FailureType>();

        if (rep.FailureEffectAnchors.Electrical != null)
        {
            modes.Add(Gremlin.FailureType.Electrical);
        }

        if (rep.FailureEffectAnchors.Pressure != null)
        {
            modes.Add(Gremlin.FailureType.Pressure);
        }

        if (rep.FailureEffectAnchors.HabitatPressure != null)
        {
            modes.Add(Gremlin.FailureType.HabitatPressure);
        }

        return(modes.ToArray());
    }
Example #27
0
    public override void Interact()
    {
        if (!PlayerManager.instance.isAlive)
        {
            return;
        }

        base.Interact();

        // Get colliders
        Collider2D[] hits = Physics2D.OverlapCircleAll(PlayerManager.instance.interactArea.position, attackRange, hammerMask);

        // Damage trees
        foreach (Collider2D hit in hits)
        {
            IRepairable repairable = hit.gameObject.GetComponent <IRepairable>();
            if (repairable != null)
            {
                repairable.Repair(repairAmount);
            }
            break;
        }
    }
Example #28
0
 public void DealRepair(float repairDealt, IRepairable r)
 {
     r.TakeRepair(RepairFactor);
 }
 public void RegisterRepairee(IRepairable d)
 {
     this.repairable = d;
     d.RepairStation = this;
 }
 public void DeregisterRepairee(IRepairable d)
 {
     d.RepairStation = null;
     repairable = null;
 }
Example #31
0
 public static bool CanHavePressureFailure(this IRepairable rep)
 {
     return(rep.FailureEffectAnchors.Pressure != null);
 }
 public void DeregisterRepairee(IRepairable r)
 {
     repairee = null;
     SetPowerUsage();
 }
Example #33
0
    private FailureType GetRandomFailType(IRepairable victim)
    {
        FailureType[] failureModes = victim.GetFailureModes();

        return(failureModes[UnityEngine.Random.Range(0, failureModes.Length)]);
    }
 public bool IsAvailable(IRepairable p)
 {
     if (Power != null)
     {
         return Power.PowerOn && CanUse(p);
     }
     return CanUse(p);
 }
 public void RegisterRepairee(IRepairable r)
 {
     this.repairee = r;
     SetPowerUsage();
 }
 private bool CanUse(IRepairable p)
 {
     return repairee == null || repairee == p;
 }