/*
 * The MIT License
 *
 * Copyright 2015 AE97
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package net.ae97.notlet.entity;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import net.ae97.notlet.Location;
import net.ae97.notlet.network.packets.AttackRequestPacket;
import net.ae97.notlet.network.packets.MoveRequestPacket;
import net.ae97.notlet.network.packets.Packet;
import net.ae97.notlet.server.level.Level;

/**
 * Created by john on 11/22/15.
 */
public class Player extends Entity {

    private final Queue<Packet> requests = new LinkedList<>();
    private int score;
    private int attackCooldown;

    public Player(Location loc) {
        super(loc, 100, 200, "rangerD", 0.05, 32);
    }

    @Override
    public void processTick(Level level) {
        synchronized (requests) {
            List<Packet> uniqueRequests = selectFirstUniquePackets(requests);
            for (Packet packet : uniqueRequests) {
                switch (packet.getType()) {
                    case MoveRequest: {
                        MoveRequestPacket request = (MoveRequestPacket) packet;
                        Location old = getLocation();
                        Location newLocation = old;
                        switch (request.getDirection()) {
                            case LEFT:
                                newLocation = new Location(old.getX() - 16, old.getY());
                                break;
                            case RIGHT:
                                newLocation = new Location(old.getX() + 16, old.getY());
                                break;
                            case UP:
                                newLocation = new Location(old.getX(), old.getY() - 16);
                                break;
                            case DOWN:
                                newLocation = new Location(old.getX(), old.getY() + 16);
                                break;
                        }
                        if (level.isPassable(newLocation)) {
                            setLocation(newLocation);
                        }
                    }
                    break;
                    case AttackRequest: {
                        AttackRequestPacket request = (AttackRequestPacket) packet;
                        Location old = getLocation();
                        Location spawnLocation = old;
                        switch (request.getDirection()) {
                            case LEFT:
                                spawnLocation = new Location(old.getX() - 16.0001, old.getY());
                                break;
                            case RIGHT:
                                spawnLocation = new Location(old.getX() + 16.0001, old.getY());
                                break;
                            case UP:
                                spawnLocation = new Location(old.getX(), old.getY() - 16.0001);
                                break;
                            case DOWN:
                                spawnLocation = new Location(old.getX(), old.getY() + 16.0001);
                                break;
                        }
                        if (level.isPassable(spawnLocation)) {
                            level.spawnEntity(new Arrow(spawnLocation, request.getDirection()));
                        }
                    }
                    break;
                }
            }
            requests.clear();
        }
        if (attackCooldown > 0) {
            attackCooldown--;
        }
    }

    public void addToQueue(Packet p) {
        synchronized (requests) {
            requests.add(p);
        }
    }

    public void addScore(int value) {
        score += value;
    }

    public int getScore() {
        return score;
    }

    private List<Packet> selectFirstUniquePackets(Queue<Packet> packetRequests) {
        List<Packet> packets = new LinkedList<>();
        boolean unique;
        for (Packet p : packetRequests) {
            unique = true;
            for (Packet t : packets) {
                if (p.isEqual(t)) {
                    unique = false;
                    break;
                }
            }
            if (unique) {
                packets.add(p);
            }
        }

        return packets;
    }
}

@@ -3225,32 +3225,144 @@
 ttackRequest: %7B%0A
+                        if (attackCooldown != 0) %7B%0A                            break;%0A                        %7D%0A
                 
@@ -4472,24 +4472,73 @@
 ection()));%0A
+                            attackCooldown = 10;%0A
             

Add cooldown logic