Exemple #1
0
        public override void Tick(RealmTime time)
        {
            try
            {
                if (Size == 0 && MType != -1)
                {
                    Size = MERCHANT_SIZE;
                    UpdateCount++;
                }

                if (!closing)
                {
                    tickcount++;
                    if (tickcount % (Manager?.TPS * 60) == 0) //once per minute after spawning
                    {
                        MTime--;
                        UpdateCount++;
                    }
                }

                if (MRemaining == 0 && MType != -1)
                {
                    if (AddedTypes.Contains(new KeyValuePair <string, int>(Owner.Name, MType)))
                    {
                        AddedTypes.Remove(new KeyValuePair <string, int>(Owner.Name, MType));
                    }
                    Recreate(this);
                    UpdateCount++;
                }

                if (MTime == -1 && Owner != null)
                {
                    if (AddedTypes.Contains(new KeyValuePair <string, int>(Owner.Name, MType)))
                    {
                        AddedTypes.Remove(new KeyValuePair <string, int>(Owner.Name, MType));
                    }
                    Recreate(this);
                    UpdateCount++;
                }

                if (MTime == 1 && !closing)
                {
                    closing = true;
                    Owner?.Timers.Add(new WorldTimer(30 * 1000, (w1, t1) =>
                    {
                        MTime--;
                        UpdateCount++;
                        w1.Timers.Add(new WorldTimer(30 * 1000, (w2, t2) =>
                        {
                            MTime--;
                            UpdateCount++;
                        }));
                    }));
                }

                if (MType == -1)
                {
                    Owner?.LeaveWorld(this);
                }

                base.Tick(time);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
        public override void Tick(RealmTime time)
        {
            try
            {
                if (Size == 0 && MType != -1)
                {
                    Size = merchantSize;
                    UpdateCount++;
                }

                if (!closing)
                {
                    tickcount++;
                    if (Manager != null)
                    {
                        if (tickcount % (Manager.TPS * 60) == 0) //once per minute after spawning
                        {
                            MTime--;
                            UpdateCount++;
                        }
                    }
                }

                if (MRemaining == 0 && MType != -1)
                {
                    if (AddedTypes.Contains(new KeyValuePair <string, int>(Owner.Name, MType)))
                    {
                        AddedTypes.Remove(new KeyValuePair <string, int>(Owner.Name, MType));
                    }
                    Recreate(this);
                    UpdateCount++;
                }

                if (MTime == -1 && Owner != null)
                {
                    if (AddedTypes.Contains(new KeyValuePair <string, int>(Owner.Name, MType)))
                    {
                        AddedTypes.Remove(new KeyValuePair <string, int>(Owner.Name, MType));
                    }
                    Recreate(this);
                    UpdateCount++;
                }

                if (MTime == 1 && !closing)
                {
                    closing = true;
                    if (Owner != null)
                    {
                        Owner.Timers.Add(new WorldTimer(30 * 1000, (w1, t1) =>
                        {
                            MTime--;
                            UpdateCount++;
                            w1.Timers.Add(new WorldTimer(30 * 1000, (w2, t2) =>
                            {
                                MTime--;
                                UpdateCount++;
                            }));
                        }));
                    }
                }

                if (!MerchantLists.NoDiscountList.Contains(MType))
                {
                    int s = MRemaining;

                    if (s <= 2)
                    {
                        Discount = 50;
                    }
                    else if (s <= 5)
                    {
                        Discount = 25;
                    }
                    else if (s <= 10)
                    {
                        Discount = 15;
                    }
                    else if (s <= 15)
                    {
                        Discount = 10;
                    }
                    else
                    {
                        Discount = 0;
                    }

                    Tuple <int, CurrencyType> price;
                    if (prices.TryGetValue(MType, out price))
                    {
                        Price = (int)(price.Item1 - (price.Item1 * ((double)Discount / 100))) < 1 ? price.Item1 : (int)(price.Item1 - (price.Item1 * ((double)Discount / 100)));
                    }
                }

                if (MType == -1 && Owner != null)
                {
                    Owner.LeaveWorld(this);
                }

                base.Tick(time);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }