Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.albionstarterproject.controller;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- import org.json.JSONException;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import com.albionstarterproject.service.GetPricesService;
- @Controller
- public class T4HideRefineController {
- @GetMapping("t4hide.html/calculate")
- public String calculate(
- @RequestParam(name = "returnRate") String returnRate,
- @RequestParam(name = "amountOfRawMaterial") String amountOfRawMaterial,
- @RequestParam(name = "priceOfRawMaterial") String priceOfRawMaterial,
- @RequestParam(name = "amountOfRefinedResource") String amountOfRefinedResource,
- @RequestParam(name = "priceOfRefinedResource") String priceOfRefinedResource,
- @RequestParam(name = "refinedResourcePrice") String refinedResourcePrice,
- @RequestParam(name = "totalRefined") String totalRefined, Model model) {
- if (returnRate.equals(""))
- returnRate = "15";
- else if (Integer.parseInt(returnRate) > 55) {
- totalRefined = "It is not possible to have " + returnRate + "% return rate!";
- } else {
- int amountOfRawMaterialInt = Integer.parseInt(amountOfRawMaterial);
- while (amountOfRawMaterialInt % 4 != 0) amountOfRawMaterialInt--;
- amountOfRawMaterialInt /= 4;
- int total = amountOfRawMaterialInt;
- int ret = Integer.parseInt(returnRate);
- while (amountOfRawMaterialInt > 0) {
- amountOfRawMaterialInt = amountOfRawMaterialInt * ret / 100;
- total += amountOfRawMaterialInt;
- }
- totalRefined = "" + total;
- amountOfRefinedResource = totalRefined;
- }
- Map<String, String> map = new HashMap<>();
- map.put("amountOfRawMaterial", amountOfRawMaterial);
- map.put("priceOfRawMaterial", priceOfRawMaterial);
- map.put("amountOfRefinedResource", amountOfRefinedResource);
- map.put("priceOfRefinedResource", priceOfRefinedResource);
- map.put("refinedResourcePrice", refinedResourcePrice);
- map.put("totalRefined", totalRefined);
- map.put("returnRate", returnRate);
- model.addAllAttributes(map);
- model.addAttribute("profit", "34545");
- model.addAttribute("spent", "34545");
- model.addAttribute("income", "34545");
- return "t4hide";
- }
- @GetMapping("t4hide.html/getPrices")
- public String getPrices(@RequestParam(name = "city") String city,
- @RequestParam(name="rawMaterial") String rawMaterial,
- @RequestParam(name="refinedMaterial") String refinedMaterial,
- @RequestParam(name="refineResult") String refineResult,
- @RequestParam(name="returnRate") String returnRate,
- Model model) throws JSONException, IOException, InterruptedException {
- GetPricesService gps = new GetPricesService();
- if (city.equals("Fort Sterling")) city = "FortSterling";
- model.addAttribute("priceOfRawMaterial", gps.getCityPrice("https://www.albion-online-data.com/api/v2/stats/prices/" + rawMaterial + "?locations=" + city));
- model.addAttribute("priceOfRefinedResource", gps.getCityPrice("https://www.albion-online-data.com/api/v2/stats/prices/" + refinedMaterial + "?locations=" + city));
- model.addAttribute("refinedResourcePrice", gps.getCityPrice("https://www.albion-online-data.com/api/v2/stats/prices/" + refineResult + "?locations=" + city));
- System.out.println(returnRate);
- return "t4hide";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement