예제 #1
0
 private void AcquireTarget()
 {
     this.target = ActiveSubroutines.FindClosestMalware(this.transform.position, 999f);
     this.lerpFrom = this.transform.position;
     CurrentIterationTime = 0f;
     IterationTime = 1f;
 }
예제 #2
0
 internal void UpdateIcon(IMalware second, int first)
 {
     switch(second.Type)
     {
         case VirusAI.VirusType.Virus:
             UpdateIcon(VirusAmount, first);
             break;
         case VirusAI.VirusType.Wabbit:
             UpdateIcon(WabbitAmount, first);
             break;
         case VirusAI.VirusType.Trojan:
             UpdateIcon(TrojanAmount, first);
             break;
         case VirusAI.VirusType.Tank:
             UpdateIcon(TankAmount, first);
             break;
         case VirusAI.VirusType.Spawner:
             UpdateIcon(SpawnerAmount, first);
             break;
         case VirusAI.VirusType.Ransomware:
             UpdateIcon(RansomwareAmount, first);
             break;
         case VirusAI.VirusType.Bomb:
             UpdateIcon(BombAmount, first);
             break;
         case VirusAI.VirusType.Stealth:
             UpdateIcon(StealthAmount, first);
             break;
     }
 }
    public static void AddVirus(IMalware newVirus)
    {
        Machine m = CyberspaceBattlefield.Current.FindByName(newVirus.transform.root.name);
        if (m == null)
        {
            UnityEngine.Debug.LogWarning("No machine found to add virus to!");
        }
        else
        {
            MalwareList.Add(newVirus);

            if (newVirus.IsLurking())
            {
                m.LurkingMalware.Add(newVirus);
            }
            else
            {
                if (!m.IsInfected)
                {
                    m.StartReinfection();
                }
                m.ActiveMalware.Add(newVirus);
            }

            if (OnMalwareListChange != null)
                OnMalwareListChange(null);
        }
    }
예제 #4
0
    private void FireAtEnemy(Vector3 relativePos, IMalware m)
    {
        isFiring = true;
        CooldownRemaining = this.Parent.Cooldown;

        Transform laserStart;
        if (onPrimary)
            laserStart = leftGun;
        else
            laserStart = rightGun;

        onPrimary = !onPrimary;

        Transform t = (Transform)Instantiate(lazerPrefab, laserStart.position, laserStart.rotation);

        LazerTorpedo b = t.GetComponent<LazerTorpedo>();
        if (b != null)
        {
            b.origin = this.Parent;
            b.FireTorpedo(m);
        }

        Physics.IgnoreCollision(this.GetComponent<Collider>(), t.GetComponent<Collider>());

        StartCoroutine(this.WaitCooldown());
    }
예제 #5
0
 private void OnMalwareListChange(IMalware dead)
 {
     if (isActiveAndEnabled && CanReplenishMalware && (dead != null) && (dead.gameObject.transform.root.name == this.gameObject.transform.root.name))
     {
         malwareQueue += 1;
         //if there is no active coroutine, start it
         if (Replenish == null)
         {
             Replenish = StartCoroutine(ReplenishMalware());
         }
     }
 }
예제 #6
0
 private void OnMalwareListChange(IMalware dead)
 {
     if (ActiveSubroutines.MalwareList.Count > 0 && ActiveSubroutines.MalwareList.TrueForAll(m => m.IsLurking()))
     {
         //only lurkers! pop them all!
         foreach(IMalware imal in ActiveSubroutines.MalwareList)
         {
             (imal as ILurker).OnSubnetSupposedlyClean();
         }
         ScanAndPrint(null);
     }
     else if (ActiveSubroutines.MalwareList.Count == 0)
     {
         OnWin();
     }
     else
     {
         ScanAndPrint(dead);
     }
 }
예제 #7
0
    protected void FindClosestMalware()
    {
        if (ActiveSubroutines.MalwareList.Count == 0)
        {
            this.lockedMalware = null;
            this.lockedVirus = null;
            this._lockedTarget = null;
            return;
        }

        float range = 500;
        //comparing range squared vs magnitude squared is a performance enhancement
        //it eliminates the expensive square root calculation
        float closest = range * range;
        foreach (IMalware mal in ActiveSubroutines.MalwareList)
        {
            if (mal.IsLurking())
                continue;

            float dist = (mal.transform.position - this.transform.position).sqrMagnitude / mal.AttackPriority;
            //if this has a higher priority than now
            //and the distance is closer
            if (dist < closest)
            {
                if (!this.Function.OnlyTrackActiveViruses || (mal is VirusAI))
                {
                    _lockedTarget = mal.transform;
                    this.lockedMalware = mal;

                    if (mal is VirusAI)
                        this.lockedVirus = mal as VirusAI;

                    closest = dist;
                }
            }
        }
    }
예제 #8
0
 private void ScanAndPrint(IMalware dead)
 {
     Dictionary<string, Tuple<int, IMalware>> malwareTypes = new Dictionary<string, Tuple<int, IMalware>>();
     foreach (IMalware imal in ActiveSubroutines.MalwareList)
     {
         if (imal.IsLurking())
         {
             continue;
         }
         if (malwareTypes.ContainsKey(imal.GetType().Name))
         {
             Tuple<int, IMalware> thisRecord = malwareTypes[imal.GetType().Name];
             malwareTypes[imal.GetType().Name] = new Tuple<int, IMalware>(thisRecord.First + 1, thisRecord.Second);
         }
         else
         {
             malwareTypes.Add(imal.GetType().Name, new Tuple<int, IMalware>(1, imal));
         }
     }
     PrintToIcons(malwareTypes, dead);
     //PrintToAI(malwareTypes);
     //PrintToConsole(malwareTypes);
 }
예제 #9
0
    private void PrintToIcons(Dictionary<string, Tuple<int, IMalware>> malwareTypes, IMalware dead)
    {
        if (VirusIconDisplay.Instance != null)
        {
            if (dead != null && !malwareTypes.ContainsKey(dead.GetType().Name))
            {
                malwareTypes.Add(dead.GetType().Name, new Tuple<int, IMalware>(0, dead));
            }

            foreach (Tuple<int, IMalware> rec in malwareTypes.Values)
            {
                VirusIconDisplay.Instance.UpdateIcon(rec.Second, rec.First);
            }
        }
    }
예제 #10
0
    public static void RemoveVirus(IMalware oldVirus)
    {
        Machine m = CyberspaceBattlefield.Current.FindByName(oldVirus.transform.root.name);
        if (m != null)
        {
            m.ActiveMalware.Remove(oldVirus);
            if (m.ActiveMalware.Count == 0){

                if (CyberspaceBattlefield.Current.Abdicate)
                {
                    //noop
                }
                else if (m.IsInfected)
                {
                    if (m.LurkingMalware.Count > 0)
                    {
                        foreach(ILurker l in m.LurkingMalware)
                        {
                            l.OnMachineClean();
                        }
                    }

                    m.DoOnMachineClean();
                }
                else if (m.IsBeingReinfected)
                {
                    m.DoOnMachineReinfectionStopped();
                }
            }
        }
        else
        {
            Debug.LogWarning("cant find machine to remove virus from activemalware list");
        }

        if (!MalwareList.Remove(oldVirus))
            Debug.LogWarning("Could not remove virus!");

        if (OnMalwareListChange != null)
            OnMalwareListChange(oldVirus);

        //UnityEngine.Debug.Log("still: " + (MalwareList.Count) + " malware");
        //MalwareList.ForEach(a => UnityEngine.Debug.Log("still here: "+a.transform.name));
    }