Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

public boolean containsItem(String id) { Iterator var3 = this.items.iterator();…

  1. User

    public boolean containsItem(String id) { Iterator var3 = this.items.iterator();

      while(var3.hasNext()) {
         Item item = (Item)var3.next();
         if (item.id.equals(id)) {
            return true;
         }
      }
    
      return false;
    

    }

    public Item getItemById(String id) { Iterator var3 = this.items.iterator();

      while(var3.hasNext()) {
         Item item = (Item)var3.next();
         if (item.id.equals(id)) {
            return item;
         }
      }
    
      return null;
    

    }

    public boolean mountItem(String id) { Item item = this.getItemById(id.substring(0, id.length() - 3)); if (item != null && Integer.parseInt(id.substring(id.length() - 1, id.length())) == item.modificationIndex) { if (item.itemType == ItemType.WEAPON) { this.mountTurret = item; return true; }

         if (item.itemType == ItemType.ARMOR) {
            this.mountHull = item;
            return true;
         }
    
         if (item.itemType == ItemType.COLOR) {
            this.mountColormap = item;
            return true;
         }
      }
    
      return false;
    

    }

    public boolean updateItem(String id) { Item item = this.getItemById(id.substring(0, id.length() - 3)); int modificationID = Integer.parseInt(id.substring(id.length() - 1)); if (modificationID < 3 && item.modificationIndex == modificationID) { ++item.modificationIndex; item.nextPrice = item.modifications[item.modificationIndex + 1 != 4 ? item.modificationIndex + 1 : item.modificationIndex].price; item.nextProperty = item.modifications[item.modificationIndex + 1 != 4 ? item.modificationIndex + 1 : item.modificationIndex].propertys; item.nextRankId = item.modifications[item.modificationIndex + 1 != 4 ? item.modificationIndex + 1 : item.modificationIndex].rank; this.replaceItems(this.getItemById(id.substring(0, id.length() - 3)), item); return true; } else { return false; } }

    public boolean buyItem(String id, int count) { Item temp = (Item)GarageItemsLoader.items.get(id.substring(0, id.length() - 3)); if (temp.specialItem) { return false; } else { Item item = temp.clone(); if (!this.items.contains(this.getItemById(id))) { if (item.isInventory) { item.count += count; }

            this.items.add(item);
            return true;
         } else if (item.isInventory) {
            Item fromUser = this.getItemById(id);
            fromUser.count += count;
            return true;
         } else {
            return false;
         }
      }
    

    }

    public Item buyItem(String id, int count, int nul) { id = id.substring(0, id.length() - 3); Item temp = (Item)GarageItemsLoader.items.get(id); if (temp.specialItem) { return null; } else { Item item = temp.clone(); if (!this.items.contains(this.getItemById(id))) { if (item.itemType == ItemType.INVENTORY) { item.count += count; }

          // Проверка, на то что id предмета не равен косярю опыта
            if (!id.equals("1000_scores")) {
               this.items.add(item);
            }
            return item;
         } else if (item.itemType == ItemType.INVENTORY) {
            Item fromUser = this.getItemById(id);
            fromUser.count += count;
            return fromUser;
         } else {
            return null;
         }
      }
    

    }

    public int getItemCount() { return this.items.size(); }

    private void replaceItems(Item old, Item newItem) { if (this.items.contains(old)) { this.items.set(this.items.indexOf(old), newItem); }

    }

    public ArrayList getInventoryItems() { ArrayList _items = new ArrayList(); Iterator var3 = this.items.iterator();

      while(var3.hasNext()) {
         Item item = (Item)var3.next();
         if (item.itemType == ItemType.INVENTORY) {
            _items.add(item);
         }
      }
    
      return _items;
    

    }

    public void parseJSONData() { JSONObject hulls = new JSONObject(); JSONArray _hulls = new JSONArray(); JSONObject colormaps = new JSONObject(); JSONArray _colormaps = new JSONArray(); JSONObject turrets = new JSONObject(); JSONArray _turrets = new JSONArray(); JSONObject inventory_items = new JSONObject(); JSONArray _inventory = new JSONArray(); JSONObject effects_items = new JSONObject(); JSONArray _effects = new JSONArray(); Iterator var10 = this.items.iterator();

      while(var10.hasNext()) {
         Item item = (Item)var10.next();
         JSONObject inventory;
         if (item.itemType == ItemType.ARMOR) {
            inventory = new JSONObject();
            inventory.put("discount", item.discount);
            inventory.put("id", item.id);
            inventory.put("modification", item.modificationIndex);
            inventory.put("mounted", item == this.mountHull);
            _hulls.add(inventory);
         }
    
         if (item.itemType == ItemType.COLOR) {
            inventory = new JSONObject();
            inventory.put("id", item.id);
            inventory.put("discount", item.discount);
            inventory.put("modification", item.modificationIndex);
            inventory.put("mounted", item == this.mountColormap);
            _colormaps.add(inventory);
         }
    
         if (item.itemType == ItemType.WEAPON) {
            inventory = new JSONObject();
            inventory.put("id", item.id);
            inventory.put("discount", item.discount);
            inventory.put("modification", item.modificationIndex);
            inventory.put("mounted", item == this.mountTurret);
            _turrets.add(inventory);
         }
    
         if (item.itemType == ItemType.INVENTORY) {
            inventory = new JSONObject();
            inventory.put("id", item.id);
            inventory.put("discount", item.discount);
            inventory.put("count", item.count);
            _inventory.add(inventory);
         }
    
         if (item.itemType == ItemType.PLUGIN) {
            inventory = new JSONObject();
            inventory.put("id", item.id);
            inventory.put("discount", item.discount);
            inventory.put("time", item.time);
            _effects.add(inventory);
         }
      }
    
      hulls.put("hulls", _hulls);
      colormaps.put("colormaps", _colormaps);
      turrets.put("turrets", _turrets);
      inventory_items.put("inventory", _inventory);
      effects_items.put("effects", _effects);
      this._json_colormaps = colormaps.toJSONString();
      this._json_hulls = hulls.toJSONString();
      this._json_turrets = turrets.toJSONString();
      this._json_inventory = inventory_items.toJSONString();
      this._json_effects = effects_items.toJSONString();
    

    }

    public void unparseJSONData() throws ParseException { this.items.clear(); JSONParser parser = new JSONParser(); JSONObject turrets = (JSONObject)parser.parse(this._json_turrets); JSONObject colormaps = (JSONObject)parser.parse(this._json_colormaps); JSONObject hulls = (JSONObject)parser.parse(this._json_hulls); JSONObject inventory; if (this._json_inventory != null && !this._json_inventory.isEmpty()) { inventory = (JSONObject)parser.parse(this._json_inventory); } else { inventory = null; } JSONObject effects; if ((this._json_effects != null) && (!this._json_effects.isEmpty())) effects = (JSONObject)parser.parse(this._json_effects); else { effects = null; }

      Iterator var7 = ((JSONArray)turrets.get("turrets")).iterator();
    
      Object inventory_item;
      JSONObject _item;
      Item item;
      while(var7.hasNext()) {
         inventory_item = var7.next();
         _item = (JSONObject)inventory_item;
         item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone();
         item.modificationIndex = (int)(long)_item.get("modification");
         item.discount = (int)(long)_item.get("discount");
         item.nextRankId = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].rank;
         item.nextPrice = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].price;
         this.items.add(item);
         if ((Boolean)_item.get("mounted")) {
            this.mountTurret = item;
         }
      }
    
      var7 = ((JSONArray)colormaps.get("colormaps")).iterator();
    
      while(var7.hasNext()) {
         inventory_item = var7.next();
         _item = (JSONObject)inventory_item;
         item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone();
         item.modificationIndex = (int)(long)_item.get("modification");
         this.items.add(item);
         if ((Boolean)_item.get("mounted")) {
            this.mountColormap = item;
         }
      }
    
      var7 = ((JSONArray)hulls.get("hulls")).iterator();
    
      while(var7.hasNext()) {
         inventory_item = var7.next();
         _item = (JSONObject)inventory_item;
         item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone();
         item.discount = (int)(long)_item.get("discount");
         item.modificationIndex = (int)(long)_item.get("modification");
         item.nextRankId = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].rank;
         item.nextPrice = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].price;
         this.items.add(item);
         if ((Boolean)_item.get("mounted")) {
            this.mountHull = item;
         }
      }
    
      if (inventory != null) {
         var7 = ((JSONArray)inventory.get("inventory")).iterator();
    
         while(var7.hasNext()) {
            inventory_item = var7.next();
            _item = (JSONObject)inventory_item;
            item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone();
            item.modificationIndex = 0;
            item.count = (int)(long)_item.get("count");
            if (item.itemType == ItemType.INVENTORY) {
               this.items.add(item);
            }
         }
      }
    
      if (effects != null) {
         var7 = ((JSONArray)effects.get("effects")).iterator();
    
         while (var7.hasNext()) {
            inventory_item = var7.next();
            _item = (JSONObject)inventory_item;
            item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone();
            item.modificationIndex = 0;
            item.time = (long)_item.get("time");
            new SimpleTimer(this, item);
            if (item.itemType == ItemType.PLUGIN) {
               this.items.add(item);
            }
         }
      }
    

    } как сделать чтобы скидки показывались ? вот часть кода из клиентсвой части public function addItem(id:Object, name:String, type:int, sort:int, crystalPrice:int, rang:int, installed:Boolean, garageElement:Boolean, count:int, preview:ImageResource, discount:int, maxModification:int, modification:int = 0, multicounted:Boolean = true) : void { var iNormal:DisplayObject = null; var iSelected:DisplayObject = null; var data:Object = {}; var access:Boolean = rang < 1 && !garageElement; data.id = id; data.name = name; data.type = type; data.typeSort = this.typeSort[type]; data.mod = modification; data.crystalPrice = crystalPrice; data.rang = garageElement ? -1 : rang; data.installed = installed; data.garageElement = garageElement; data.count = count; data.preview = preview; data.sort = sort; data.discount = discount; data.multicounted = multicounted; data.maxModification = maxModification;

  2. Assistant

    To display discounts in the client-side code, you can modify the addItem function to include the discount parameter. You can then use this parameter to determine if a discount should be applied to the item. Here's an example of how you can modify the code:

    public function addItem(id:Object, name:String, type:int, sort:int, crystalPrice:int, rang:int, installed:Boolean, garageElement:Boolean, count:int, preview:ImageResource, discount:int, maxModification:int, modification:int = 0, multicounted:Boolean = true) : void
    {
       var iNormal:DisplayObject = null;
       var iSelected:DisplayObject = null;
       var data:Object = {};
       var access:Boolean = rang < 1 && !garageElement;
       data.id = id;
       data.name = name;
       data.type = type;
       data.typeSort = this.typeSort[type];
       data.mod = modification;
       data.crystalPrice = crystalPrice;
       data.rang = garageElement ? -1 : rang;
       data.installed = installed;
       data.garageElement = garageElement;
       data.count = count;
       data.preview = preview;
       data.sort = sort;
       data.discount = discount;
       data.multicounted = multicounted;
       data.maxModification = maxModification;
    
       // Apply discount logic here
       if (data.discount > 0) {
          data.discountedPrice = Math.floor(data.crystalPrice * (1 - data.discount/100));
       } else {
          data.discountedPrice = null;
       }
    
       // Add the item to your data model or display it in the UI
       // ...
    }
    

    In this example, the discountedPrice property is added to the item data object. If the discount parameter is greater than 0, the discounted price is calculated and assigned to discountedPrice. Otherwise, discountedPrice is set to null. You can then use this property to display the discounted price in your UI.

  3. User

    мне не надо трогать клиент, мне надо сделать логику скидок на сервере java

  4. Assistant

    To implement the logic for discounts on the server-side in Java, you can modify the addItem method to calculate the discounted price based on the discount parameter. Here's an example of how you can do this:

    public void addItem(String id, String name, int type, int sort, int crystalPrice, int rang, boolean installed, boolean garageElement, int count, ImageResource preview, int discount, int maxModification, int modification, boolean multicounted) {
       // ...
       int discountedPrice = calculateDiscountedPrice(crystalPrice, discount);
       data.put("discountedPrice", discountedPrice);
       // ...
    }
    
    private int calculateDiscountedPrice(int originalPrice, int discount) {
       double discountPercentage = discount / 100.0;
       double discountedAmount = originalPrice * discountPercentage;
       int discountedPrice = (int) Math.round(originalPrice - discountedAmount);
       return discountedPrice;
    }
    

    In this example, the calculateDiscountedPrice method takes the original price and discount percentage as parameters and calculates the discounted price using simple math. The addItem method calls this method to calculate the discounted price and adds it to the data object.

    By implementing this logic on the server-side, the discounted price will be calculated and sent to the client as part of the data. The client can then display the discounted price without needing to modify the client-side code.

  5. User

    ты не тот код редактируешь, ты as 3.0 от java чтоли не можешь отличить? я ГОВОРЮ JAVA КОД РЕДАЧИТЬ НАДО

  6. Assistant

    Извините за недоразумение. Конечно, я могу редактировать код на Java. Вот пример, как можно добавить логику скидок на сервере в методе addItem():

    public void addItem(String id, String name, int type, int sort, int crystalPrice, int rang, boolean installed, boolean garageElement, int count, ImageResource preview, int discount, int maxModification, int modification, boolean multicounted) {
       // ...
       int discountedPrice = calculateDiscountedPrice(crystalPrice, discount);
       data.put("discountedPrice", discountedPrice);
       // ...
    }
    
    private int calculateDiscountedPrice(int originalPrice, int discount) {
       double discountPercentage = discount / 100.0;
       double discountedAmount = originalPrice * discountPercentage;
       int discountedPrice = (int) Math.round(originalPrice - discountedAmount);
       return discountedPrice;
    }
    

    В этом примере метод calculateDiscountedPrice принимает оригинальную цену и процент скидки в качестве параметров и вычисляет скидочную цену с помощью математических операций. Метод addItem вызывает этот метод для расчета скидочной цены и добавляет ее в объект data.

    Реализуя эту логику на сервере, скидочная цена будет вычисляться и отправляться клиенту в составе данных. Клиент сможет отображать скидочную цену, не изменяя код на стороне клиента.