// Start is called before the first frame update
 void Start()
 {
     cubeRenderer = GetComponent <Renderer>();
     cubeRenderer.material.SetColor("_Color", Color.yellow);
     perish = GetComponent <Perishable>();
     StartCoroutine(waitTime());
 }
 public void Equality() {
     var source = new LifetimeSource();
     var p = new Perishable<int>(2, source.Lifetime);
     p.AssertEquals(new Perishable<int>(2, source.Lifetime));
     p.Equals(new Perishable<int>(3, source.Lifetime)).AssertIsFalse();
     p.Equals(new Perishable<int>(2, Lifetime.Immortal)).AssertIsFalse();
 }
    public void CurrentAndFutureItems() {
        var source = new LifetimeSource();
        var p1 = new Perishable<int>(1, source.Lifetime);
        var p2 = new Perishable<int>(1, Lifetime.Immortal);
        var p = new PerishableCollection<int>();
        
        var li0 = new List<Perishable<int>>();
        p.CurrentAndFutureItems().Subscribe(e => {
            li0.Add(e);
            e.Lifetime.WhenDead(() => li0.Remove(e));
        });
        li0.AssertSequenceEquals();

        p.Add(p1);
        li0.AssertSequenceEquals(p1);
        
        var li1 = new List<Perishable<int>>();
        p.CurrentAndFutureItems().Subscribe(e => {
            li1.Add(e);
            e.Lifetime.WhenDead(() => li1.Remove(e));
        });
        li1.AssertSequenceEquals(p1);
        
        p.Add(p2.Value, p2.Lifetime);
        li0.AssertSequenceEquals(p1, p2);
        li1.AssertSequenceEquals(p1, p2);
        
        source.EndLifetime();
        li0.AssertSequenceEquals(p2);
        li1.AssertSequenceEquals(p2);
    }
    public void CurrentAndFutureItems()
    {
        var source = new LifetimeSource();
        var p1     = new Perishable <int>(1, source.Lifetime);
        var p2     = new Perishable <int>(1, Lifetime.Immortal);
        var p      = new PerishableCollection <int>();

        var li0 = new List <Perishable <int> >();

        p.CurrentAndFutureItems().Subscribe(e => {
            li0.Add(e);
            e.Lifetime.WhenDead(() => li0.Remove(e));
        });
        li0.AssertSequenceEquals();

        p.Add(p1);
        li0.AssertSequenceEquals(p1);

        var li1 = new List <Perishable <int> >();

        p.CurrentAndFutureItems().Subscribe(e => {
            li1.Add(e);
            e.Lifetime.WhenDead(() => li1.Remove(e));
        });
        li1.AssertSequenceEquals(p1);

        p.Add(p2.Value, p2.Lifetime);
        li0.AssertSequenceEquals(p1, p2);
        li1.AssertSequenceEquals(p1, p2);

        source.EndLifetime();
        li0.AssertSequenceEquals(p2);
        li1.AssertSequenceEquals(p2);
    }
    public void ConstructionProperties()
    {
        var source = new LifetimeSource();
        var p      = new Perishable <int>(2, source.Lifetime);

        p.Value.AssertEquals(2);
        p.Lifetime.AssertEquals(source.Lifetime);
    }
    public void Equality()
    {
        var source = new LifetimeSource();
        var p      = new Perishable <int>(2, source.Lifetime);

        p.AssertEquals(new Perishable <int>(2, source.Lifetime));
        p.Equals(new Perishable <int>(3, source.Lifetime)).AssertIsFalse();
        p.Equals(new Perishable <int>(2, Lifetime.Immortal)).AssertIsFalse();
    }
示例#7
0
    private void OnCollisionEnter(Collision collision)
    {
        Perishable thisPerishable  = this.GetComponent <Perishable>();
        Perishable otherPerishable = collision.gameObject.GetComponent <Perishable>();

        if (otherPerishable && !otherPerishable.onlyBomb)
        {
            if (otherPerishable.name == "Player")
            {
                otherPerishable.doDamage(damage, "self");
            }
            else
            {
                otherPerishable.doDamage(damage, "bullet");
            }
            if (shooter)
            {
                shooter.GetComponent <Turret>().addBullet();
            }
            thisPerishable.killEntity();
        }
        else
        {
            if (bounceCount < maxBounce)
            {
                Portal portal = collision.gameObject.GetComponent <Portal>();
                if (portal && !teleported)
                {
                    Portal otherPortal = portal.getLinkedPortal().GetComponent <Portal>();
                    trace.GetComponent <Perishable>().setTarget(null);
                    Vector3 bulletToPortal = transform.position - portal.transform.position;
                    float   rotationDiff   = -Quaternion.Angle(portal.transform.rotation, otherPortal.transform.rotation);
                    transform.Rotate(otherPortal.transform.up, rotationDiff);

                    transform.position = otherPortal.getSpawnLocation();
                    changeDirection(transform.forward);
                    teleported = true;
                    Start();
                }
                else
                {
                    bounceCount++;
                    changeDirection(bounce(collision.GetContact(0).normal));
                }
            }
            else
            {
                thisPerishable.killEntity();
                if (shooter)
                {
                    shooter.GetComponent <Turret>().addBullet();
                }
            }
        }
    }
 // Update is called once per frame
 void Update()
 {
     Collider[] hitColliders = Physics.OverlapSphere(GetComponent <Transform>().position, detonationRadius);
     for (int i = 0; i < hitColliders.Length; i++)
     {
         Perishable otherPerishable = hitColliders[i].gameObject.GetComponent <Perishable>();
         if (otherPerishable != null && bomber.gameObject != hitColliders[i].gameObject)
         {
             StartCoroutine(bombBlink());
             StartCoroutine(explode());
             started = true;
         }
     }
 }
    public void CurrentItems() {
        var source = new LifetimeSource();
        var p1 = new Perishable<int>(1, source.Lifetime);
        var p2 = new Perishable<int>(1, Lifetime.Immortal);
        var p = new PerishableCollection<int>();
        p.CurrentItems().AssertSequenceEquals();

        p.Add(p1);
        p.CurrentItems().AssertSequenceEquals(p1);

        p.Add(p2.Value, p2.Lifetime);
        p.CurrentItems().AssertSequenceEquals(p1, p2);
        
        source.EndLifetime();
        p.CurrentItems().AssertSequenceEquals(p2);
    }
    IEnumerator explode()
    {
        while (true)
        {
            yield return(new WaitForSeconds(detonationActivateTime));

            Collider[] hitColliders = Physics.OverlapSphere(GetComponent <Transform>().position, detonationRadius);
            for (int i = 0; i < hitColliders.Length; i++)
            {
                Perishable otherPerishable = hitColliders[i].gameObject.GetComponent <Perishable>();
                if (otherPerishable)
                {
                    otherPerishable.doDamage(damage, "bomb");
                }
            }
            perish.doDamage(1, "self");
        }
    }
    public void CurrentItems()
    {
        var source = new LifetimeSource();
        var p1     = new Perishable <int>(1, source.Lifetime);
        var p2     = new Perishable <int>(1, Lifetime.Immortal);
        var p      = new PerishableCollection <int>();

        p.CurrentItems().AssertSequenceEquals();

        p.Add(p1);
        p.CurrentItems().AssertSequenceEquals(p1);

        p.Add(p2.Value, p2.Lifetime);
        p.CurrentItems().AssertSequenceEquals(p1, p2);

        source.EndLifetime();
        p.CurrentItems().AssertSequenceEquals(p2);
    }
示例#12
0
        public static void Prefix(Perishable __instance)
        {
            Item item = __instance.Item;

            if (item != null && item.IsFood)
            {
                if (__instance.DepletionRate != 0f)
                {
                    __instance.SetDurabilityDepletion(0f);
                    LOGGER.LogDebug(string.Format("StopFoodDecay::Perishable.ItemParentChanged: {0}, SetDurabilityDepletion set to {1}.", __instance.name, 0f));
                }
                if (!__instance.DontPerishInWorld)
                {
                    __instance.DontPerishInWorld = true;
                    LOGGER.LogDebug(string.Format("StopFoodDecay::Perishable.ItemParentChanged: {0}, DontPerishInWorld is now {1}.", __instance.name, __instance.DontPerishInWorld));
                }
                if (!__instance.DontPerishSkipTime)
                {
                    __instance.DontPerishSkipTime = true;
                    LOGGER.LogDebug(string.Format("StopFoodDecay::Perishable.ItemParentChanged: {0}, DontPerishSkipTime is now {1}.", __instance.name, __instance.DontPerishSkipTime));
                }
            }
        }
    public void ToPerishableCollectionWithLifetime()
    {
        var source           = new LifetimeSource();
        var collectionSource = new LifetimeSource();
        var p1 = new Perishable <int>(1, source.Lifetime);
        var p2 = new Perishable <int>(1, Lifetime.Immortal);
        var p  = new PerishableCollection <int>();
        var q  = p.CurrentAndFutureItems().ToPerishableCollection(collectionSource.Lifetime);

        q.CurrentItems().AssertSequenceEquals();

        p.Add(p1);
        q.CurrentItems().AssertSequenceEquals(p1);

        collectionSource.EndLifetime();

        p.Add(p2.Value, p2.Lifetime);
        q.CurrentItems().AssertSequenceEquals(p1);

        source.EndLifetime();

        source.EndLifetime();
        q.CurrentItems().AssertSequenceEquals();
    }
示例#14
0
 public static void Update(Perishable __instance)
 {
     try
     {
         if (__instance.Item.ItemID == (int)eItemIDs.Waterskin && __instance.Item.CurrentDurability == 0f && __instance.Item.IsFirstSyncDone)
         {
             //WorkInProgress.Instance.MyLogger.LogDebug($"Perishable_Update[{__instance.name}]: IsFirstSyncDone={__instance.Item.IsFirstSyncDone} / CurrentDurability={__instance.Item.CurrentDurability}");
             // When waterskin expires, replace the water with Rancid Water and remove the durability
             //WorkInProgress.Instance.MyLogger.LogDebug($"Perishable_Update[{__instance.name}]: Fill Rancid");
             (__instance.Item as global::WaterContainer).Fill(WaterType.Rancid, (__instance.Item as global::WaterContainer).RemainingUse);
             AccessTools.Field(typeof(Perishable), "m_baseDepletionRate").SetValue(__instance.Item.GetComponent <Perishable>(), 0f);
             AccessTools.Field(typeof(Item), "m_currentDurability").SetValue(__instance.Item, -1);
             AccessTools.Field(typeof(ItemStats), "m_baseMaxDurability").SetValue(__instance.Item.GetComponent <ItemStats>(), -1);
             if (__instance.Item.OwnerCharacter)
             {
                 __instance.Item.OwnerCharacter.CharacterUI.ShowInfoNotification("Water has turned rancid!", __instance.Item);
             }
         }
     }
     catch (Exception ex)
     {
         WorkInProgress.Instance.MyLogger.LogError("Update: " + ex.Message);
     }
 }
示例#15
0
        private void PerishableItemParentChanged_SFDPatch(On.Perishable.orig_ItemParentChanged orig, Perishable self)
        {
            if (self.Item != null)
            {
                if (self.Item.IsFood)
                {
                    if (self.DepletionRate != 0f)
                    {
                        self.SetDurabilityDepletion(0f);
                        Debug.Log(String.Format("StopFoodDecay::Perishable.ItemParentChanged: {0}, SetDurabilityDepletion set to {1}.", self.name, 0f));
                    }

                    if (!self.DontPerishInWorld)
                    {
                        self.DontPerishInWorld = true;
                        Debug.Log(String.Format("StopFoodDecay::Perishable.ItemParentChanged: {0}, DontPerishInWorld is now {1}.", self.name, self.DontPerishInWorld));
                    }

                    if (!self.DontPerishSkipTime)
                    {
                        self.DontPerishSkipTime = true;
                        Debug.Log(String.Format("StopFoodDecay::Perishable.ItemParentChanged: {0}, DontPerishSkipTime is now {1}.", self.name, self.DontPerishSkipTime));
                    }
                }
            }

            orig(self);
        }
 public void ConstructionProperties() {
     var source = new LifetimeSource();
     var p = new Perishable<int>(2, source.Lifetime);
     p.Value.AssertEquals(2);
     p.Lifetime.AssertEquals(source.Lifetime);
 }
示例#17
0
        static public void RunOption(int option)
        {
            Console.Clear();
            switch (option)
            {
            case 1:    //1. SET BUDGET

                if (Cart.Budget == 0)
                {
                    Console.WriteLine("--THE BUDGET HAS NOT BEEN SET--");
                }
                else
                {
                    Console.WriteLine("--THE BUDGET IS CURRENTLY: $" + Cart.Budget + "--");
                }
                Console.WriteLine("--INPUT A BUDGET--");

                //UNIT TESTING PROOF OF CONCEPT, HARCODING INPUT
                //StringReader testInput = new StringReader("200");
                //Console.SetIn(testInput);

                Cart.Budget = ReadValidPrice();
                break;

            case 2:    //2. VIEW CART

                Console.WriteLine("--VIEW CART--");
                Cart.WriteCart();

                Console.WriteLine("\n--BUDGET INFORMATION--");
                Cart.WriteBudget();

                Console.WriteLine("\nPRESS ENTER TO CONTINUE");
                Console.ReadLine();
                break;

            case 3:    //3. ADD ITEM TO CART

                Console.WriteLine("--ADD ITEM TO CART--");

                //BASE ITEM PROPERTIES
                Console.WriteLine("WHAT IS THE NAME OF YOUR ITEM:");
                string name = Console.ReadLine();
                Console.WriteLine("WHAT IS THE PRICE OF YOUR ITEM:");
                double price = ReadValidPrice();

                Item item = new Item(name, price);    //SET ITEM PROPERTIES

                Console.WriteLine("IS YOUR ITEM:");
                Console.WriteLine("\t1. CLOTHING \n\t2. FOOD \n\t3. OTHER");
                int selection = ReadValidSelection(1, 3);
                //BASE CLOTHING PROPERTIES
                if (selection == 1)
                {
                    Console.WriteLine("IS YOUR CLOTHING SIZE:");
                    Console.WriteLine("\t1. S\n\t2. M\n\t3. L\n\t4. XL");
                    int size = ReadValidSelection(1, 4);

                    Clothing clothing = new Clothing(item, (Clothing.Sizes)size);    //SET CLOTHING PROPERTIES

                    Console.WriteLine("IS YOUR CLOTHING FOR:");
                    Console.WriteLine("\t1. SAFTEY \n\t2. CASUAL");
                    selection = ReadValidSelection(1, 2);
                    //SAFTEY CLOTHING PROPERTIES
                    if (selection == 1)
                    {
                        Console.WriteLine("WHAT IS THE SAFTEY RATING OF YOUR CLOTHING:");
                        Console.WriteLine("\t1. L\n\t2. M\n\t3. H");
                        int safteyRating = ReadValidSelection(1, 3);

                        item = new Safety(clothing, (Safety.Ratings)safteyRating);    //SET SAFTEY PROPERTIES
                    }
                    //CASUAL CLOTHING PROPERTIES
                    else if (selection == 2)
                    {
                        Console.WriteLine("WHAT IS THE STYLE OF YOUR CLOTHING:");
                        Console.WriteLine("\t1. Day Wear\n\t2. Night Wear\n\t3. Swim Wear");
                        int style = ReadValidSelection(1, 3);

                        item = new Casual(clothing, (Casual.Styles)style);    //SET CASUAL PROPERTIES
                    }
                }
                //BASE FOOD PROPERTIES
                else if (selection == 2)
                {
                    Console.WriteLine("WHAT IS YOUR FOODS GROSS WEIGHT:");
                    double grossWeight = ReadValidPrice();

                    Food food = new Food(item, grossWeight);    //SET FOOD PROPERTIES

                    Console.WriteLine("IS YOUR FOOD ITEM:");
                    Console.WriteLine("\t1. PERISHABLE \n\t2. NON_PERISHABLE");
                    selection = ReadValidSelection(1, 2);
                    //PERISHABLE FOOD PROPERTIES
                    if (selection == 1)
                    {
                        Console.WriteLine("WHAT IS THE EXPIRY DATE OF YOUR FOOD(yyyy-mm-dd):");
                        DateTime expiryDate = ReadValidDate();

                        item = new Perishable(food, expiryDate);    //SET PERISHABLE PROPERTIES
                    }
                    //NON-PERISHABLE FOOD PROPERTIES
                    else if (selection == 2)
                    {
                        Console.WriteLine("WHAT IS THE NET WEIGHT OF YOU FOOD:");
                        double netWeight = ReadValidPrice();

                        item = new NonPerishable(food, netWeight);    //SET NON-PERISHABLE PROPERTIES
                    }
                }

                Cart.Items.Add(item);
                Console.Clear();
                Console.WriteLine("YOU HAVE ADDED THE FOLLOWING ITEM TO THE CART:");
                Console.WriteLine(item.ToString());

                Console.WriteLine("\nPRESS ENTER TO CONTINUE");
                Console.ReadLine();
                break;

            case 4:     //Remove Item From Cart

                if (Cart.Items.Count == 0)
                {
                    Console.WriteLine("YOUR CART IS EMPTY");

                    Console.WriteLine("\nPRESS ENTER TO CONTINUE");
                    Console.ReadLine();
                    break;
                }

                Console.WriteLine("--YOUR CART--");
                Cart.WriteCart();

                Console.WriteLine("\n--SELECT AN ITEM TO REMOVE--");
                int index = ReadValidSelection(1, Cart.Items.Count) - 1;
                Cart.Items.RemoveAt(index);

                Console.WriteLine("\nPRESS ENTER TO CONTINUE");
                Console.ReadLine();
                break;

            case 5:    //EXIT
                Program.Exit = true;
                break;

            default:
                break;
            }
        }