gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
const WeaponModel = require("./WeaponModel"), { getMaxDamage, getDamage } =…
- User
const WeaponModel = require("./WeaponModel"), { getMaxDamage, getDamage } = require("./server");
class ShaftModel extends WeaponModel {
onData(socket, args) { if (this.battle === null || this.user === null) return; try { if (args[0] === "quick_shot_shaft" || args[0] === "fire") { const data = JSON.parse(args[1]); let damage = 0; if (args[0] === "quick_shot_shaft") { damage = getDamage(this.name, this.modification); this.battle.broadcast("shaft_quick_shot;" + this.user.nickname + ";" + args[1]); } if (args[0] === "fire") { damage = getMaxDamage(this.name, this.modification) / 100 * (100 - data.energy / 10); this.battle.broadcast("fire;" + this.user.nickname + ";" + args[1]); } if (data.targets.length === 0) return; const target = data.targets[0]; const killer = this.user; const user = this.battle.getUser(target.target_id || target.target.id); if (user) user.attack(killer, damage, socket.tank.garage.mounted_turret, user.team_type.toUpperCase(), this.battle.getFriendlyFire()); } } catch (e) { } }}
module.exports = ShaftModel; переделай этот js код под java
- Assistant
import java.util.List; import com.google.gson.Gson;
public class ShaftModel extends WeaponModel { public void onData(Socket socket, String[] args) { if (this.battle == null || this.user == null) return; try { if (args[0].equals("quick_shot_shaft") || args[0].equals("fire")) { Gson gson = new Gson(); String dataStr = args[1]; Data data = gson.fromJson(dataStr, Data.class);
int damage = 0; if (args[0].equals("quick_shot_shaft")) { damage = getDamage(this.name, this.modification); this.battle.broadcast("shaft_quick_shot;" + this.user.nickname + ";" + args[1]); } if (args[0].equals("fire")) { damage = getMaxDamage(this.name, this.modification) / 100 * (100 - data.energy / 10); this.battle.broadcast("fire;" + this.user.nickname + ";" + args[1]); } if (data.targets.size() == 0) return; Target target = data.targets.get(0); User killer = this.user; User user = this.battle.getUser(target.target_id != null ? target.target_id : target.target.id); if (user != null) user.attack(killer, damage, socket.tank.garage.mounted_turret, user.team_type.toUpperCase(), this.battle.getFriendlyFire()); } } catch (Exception e) { } } private class Data { List<Target> targets; int energy; } private class Target { Integer target_id; User target; }}