// Path: src/main/java/com/zhaidaosi/game/server/model/Duel.java
// public class Duel {
// 
//     public static final String END = "end";
//     public static final String INIT = "init";
//     public static final String MSG = "msg";
// 
//     public static Player doDuel(Player me, Player target, DuelZone zone, String handlerName) {
//         Player hiter;
//         Player beHiter;
//         Player winer;
// 
//         zone.addPlayer(me);
//         zone.addPlayer(target);
//         BaseHandlerChannel ch = new BaseHandlerChannel(handlerName, zone.getChannelGroup());
// 
//         ch.writeGroup(Duel.write("", Duel.INIT, me, target));
// 
//         do {
//             int select = getHiter();
//             switch (select) {
//                 case 0:
//                     hiter = me;
//                     beHiter = target;
//                     break;
//                 case 1:
//                     hiter = target;
//                     beHiter = me;
//                     break;
//                 default:
//                     hiter = me;
//                     beHiter = target;
//                     break;
//             }
//             IBaseAction action = getAction(hiter);
//             try {
//                 Thread.sleep(300);
//             } catch (InterruptedException e) {
//             }
//             action.doAction(hiter, beHiter, ch);
//         } while (me.getHp() > 0 && target.getHp() > 0);
// 
//         if (me.getHp() > 0) {
//             winer = me;
//         } else {
//             winer = target;
//         }
//         ch.writeGroup(write(winer.getName() + " 获胜", END, me, target));
//         zone.close();
//         me.setHp(me.getTotalHp());
//         target.setHp(target.getTotalHp());
// 
//         me.gOldPosition().getArea().addPlayer(me);
// 
//         target.gOldPosition().getArea().addPlayer(target);
// 
//         return winer;
//     }
// 
//     public static OutMessage write(String msg, String action, Object me, Object target) {
//         Map<String, Object> out = new HashMap<String, Object>();
//         out.put("msg", msg);
//         out.put("action", action);
//         out.put("player_me", me);
//         out.put("player_target", target);
//         return OutMessage.showSucc(out);
//     }
// 
//     private static int getHiter() {
//         return new Random().nextInt(2);
//     }
// 
//     private static IBaseAction getAction(BasePlayer hiter) {
//         IBaseAction[] actions = new IBaseAction[hiter.getActions().size()];
//         actions = hiter.getActions().values().toArray(actions);
//         int select = 0;
//         if (actions.length > 1) {
//             int random = actions.length;
//             select = new Random().nextInt(random);
//         }
//         return actions[select];
//     }
// 
// }
// 
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
// 
//     private static Map<Integer, Integer> levelExperience = new HashMap<>();
// 
//     private UserInfo userInfo;
//     private BasePosition oldPosition;
//     private Map<String, Integer> actionJson = new HashMap<>();
// 
//     static {
//         levelExperience.put(1, 100);
//         levelExperience.put(2, 300);
//         levelExperience.put(3, 500);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public void init(UserInfo userInfo) {
//         this.userInfo = userInfo;
//         this.name = userInfo.getNickname();
//         this.level = userInfo.getLevel();
//         this.totalHp = this.level * 100;
//         this.hp = this.totalHp;
//         this.experience = userInfo.getExperience();
// 
//         actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
// 
//         for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
//             AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
//             attackAction.setLevel(entry.getValue());
//             this.addAction(attackAction);
//         }
// 
//         IBaseArea area = AreaManager.getArea(Area.ID);
//         area.addPlayer(this);
//     }
// 
//     public UserInfo getUserInfo() {
//         return userInfo;
//     }
// 
//     private void upLevel(int level) {
//         if (this.level != level) {
//             this.level = level;
//             userInfo.setLevel(level);
//             for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
//                 IBaseAction action = entry.getValue();
//                 if (action instanceof AttackAction) {
//                     ((AttackAction) action).setLevel(level);
//                     actionJson.put(Integer.toString(action.getId()), level);
//                 }
//                 userInfo.setActions(BaseJson.ObjectToJson(actionJson));
//             }
//         }
//     }
// 
//     public void addExperience(int experience) {
//         this.experience += experience;
//         int _level = level;
//         Integer _experience = levelExperience.get(_level);
//         while (_experience != null && this.experience > _experience) {
//             _level++;
//             _experience = levelExperience.get(_level);
//         }
//         userInfo.setExperience(this.experience);
//         upLevel(_level);
//         RsyncManager.add(id, UserInfoRsync.class, userInfo);
//     }
// 
//     public BasePosition gOldPosition() {
//         return oldPosition;
//     }
// 
//     public void sOldPosition(BasePosition oldPosition) {
//         this.oldPosition = oldPosition;
//     }
// 
// }


import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.model.action.BaseAction;
import com.zhaidaosi.game.server.model.Duel;
import com.zhaidaosi.game.server.model.player.Player;

package com.zhaidaosi.game.server.model.action;


public class AttackAction extends BaseAction {

    public static int ID = 1;

    private int level = 1;

    private int minDamage;

    private int maxDamage;

    public AttackAction() {
        super(ID, "基本攻击");
    }

    @Override
    public void doAction(Object self, Object target, BaseHandlerChannel ch) {

// Path: src/main/java/com/zhaidaosi/game/server/model/Duel.java
// public class Duel {
// 
//     public static final String END = "end";
//     public static final String INIT = "init";
//     public static final String MSG = "msg";
// 
//     public static Player doDuel(Player me, Player target, DuelZone zone, String handlerName) {
//         Player hiter;
//         Player beHiter;
//         Player winer;
// 
//         zone.addPlayer(me);
//         zone.addPlayer(target);
//         BaseHandlerChannel ch = new BaseHandlerChannel(handlerName, zone.getChannelGroup());
// 
//         ch.writeGroup(Duel.write("", Duel.INIT, me, target));
// 
//         do {
//             int select = getHiter();
//             switch (select) {
//                 case 0:
//                     hiter = me;
//                     beHiter = target;
//                     break;
//                 case 1:
//                     hiter = target;
//                     beHiter = me;
//                     break;
//                 default:
//                     hiter = me;
//                     beHiter = target;
//                     break;
//             }
//             IBaseAction action = getAction(hiter);
//             try {
//                 Thread.sleep(300);
//             } catch (InterruptedException e) {
//             }
//             action.doAction(hiter, beHiter, ch);
//         } while (me.getHp() > 0 && target.getHp() > 0);
// 
//         if (me.getHp() > 0) {
//             winer = me;
//         } else {
//             winer = target;
//         }
//         ch.writeGroup(write(winer.getName() + " 获胜", END, me, target));
//         zone.close();
//         me.setHp(me.getTotalHp());
//         target.setHp(target.getTotalHp());
// 
//         me.gOldPosition().getArea().addPlayer(me);
// 
//         target.gOldPosition().getArea().addPlayer(target);
// 
//         return winer;
//     }
// 
//     public static OutMessage write(String msg, String action, Object me, Object target) {
//         Map<String, Object> out = new HashMap<String, Object>();
//         out.put("msg", msg);
//         out.put("action", action);
//         out.put("player_me", me);
//         out.put("player_target", target);
//         return OutMessage.showSucc(out);
//     }
// 
//     private static int getHiter() {
//         return new Random().nextInt(2);
//     }
// 
//     private static IBaseAction getAction(BasePlayer hiter) {
//         IBaseAction[] actions = new IBaseAction[hiter.getActions().size()];
//         actions = hiter.getActions().values().toArray(actions);
//         int select = 0;
//         if (actions.length > 1) {
//             int random = actions.length;
//             select = new Random().nextInt(random);
//         }
//         return actions[select];
//     }
// 
// }
// 
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
// 
//     private static Map<Integer, Integer> levelExperience = new HashMap<>();
// 
//     private UserInfo userInfo;
//     private BasePosition oldPosition;
//     private Map<String, Integer> actionJson = new HashMap<>();
// 
//     static {
//         levelExperience.put(1, 100);
//         levelExperience.put(2, 300);
//         levelExperience.put(3, 500);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public void init(UserInfo userInfo) {
//         this.userInfo = userInfo;
//         this.name = userInfo.getNickname();
//         this.level = userInfo.getLevel();
//         this.totalHp = this.level * 100;
//         this.hp = this.totalHp;
//         this.experience = userInfo.getExperience();
// 
//         actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
// 
//         for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
//             AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
//             attackAction.setLevel(entry.getValue());
//             this.addAction(attackAction);
//         }
// 
//         IBaseArea area = AreaManager.getArea(Area.ID);
//         area.addPlayer(this);
//     }
// 
//     public UserInfo getUserInfo() {
//         return userInfo;
//     }
// 
//     private void upLevel(int level) {
//         if (this.level != level) {
//             this.level = level;
//             userInfo.setLevel(level);
//             for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
//                 IBaseAction action = entry.getValue();
//                 if (action instanceof AttackAction) {
//                     ((AttackAction) action).setLevel(level);
//                     actionJson.put(Integer.toString(action.getId()), level);
//                 }
//                 userInfo.setActions(BaseJson.ObjectToJson(actionJson));
//             }
//         }
//     }
// 
//     public void addExperience(int experience) {
//         this.experience += experience;
//         int _level = level;
//         Integer _experience = levelExperience.get(_level);
//         while (_experience != null && this.experience > _experience) {
//             _level++;
//             _experience = levelExperience.get(_level);
//         }
//         userInfo.setExperience(this.experience);
//         upLevel(_level);
//         RsyncManager.add(id, UserInfoRsync.class, userInfo);
//     }
// 
//     public BasePosition gOldPosition() {
//         return oldPosition;
//     }
// 
//     public void sOldPosition(BasePosition oldPosition) {
//         this.oldPosition = oldPosition;
//     }
// 
// }


// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.model.action.BaseAction;
import com.zhaidaosi.game.server.model.Duel;
import com.zhaidaosi.game.server.model.player.Player;

package com.zhaidaosi.game.server.model.action;


public class AttackAction extends BaseAction {

    public static int ID = 1;

    private int level = 1;

    private int minDamage;

    private int maxDamage;

    public AttackAction() {
        super(ID, "基本攻击");
    }

    @Override
    public void doAction(Object self, Object target, BaseHandlerChannel ch) {

        Player selfPlayer = (Player) self;
