#!/bin/bash

source ~/.gamerc

for ZONE_DIR in $WORKING_DIRECTORY/servers*/ZoneServer* ; do 
	
	cd $ZONE_DIR

#	egrep -h "$(date -d "-1 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date -d "-2 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date +"%Y/%m/%d %H:").....,EXP:[0-9]+" $(ls -tr Attrib*.log.*|tail -2)|grep -v ",Z:[0-9][0-9][0-9]:"|sed 's/^.......//g;s/EXP:[0-9]\+,//g;s/\([0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9] [0-9][0-9]:\)....../\1/g'|grep ",P:"|sort -t : -k 5|sort|uniq -dc|sort -g|grep ",P:"|awk '$1>5{print}'|sed 's/:/,/g;s/^ \+\([0-9]\+\) /\1,/g' > multi-kill-same-mobs-list

#	for char_name in `awk -F, '{print $10}' multi-kill-same-mobs-list |sort -g|uniq`;do  char_name="$(echo "$char_name"| sed 's/\[/\\[/g;s/\]/\\]/g')";GOT_TIMES="$(grep ",$char_name," multi-kill-same-mobs-list|wc -l)";KILLS="$(($(grep ",$char_name," multi-kill-same-mobs-list|awk -F, '{print $1}'|tr '\n' '+')0))";MAX_X="$(grep ",$char_name," multi-kill-same-mobs-list|awk -F, '{print $(NF-1)}'|sort -rg|head -1)";MAX_Y="$(grep ",$char_name," multi-kill-same-mobs-list|awk -F, '{print $NF}'|sort -rg|head -1)";MIN_X="$(grep ",$char_name," multi-kill-same-mobs-list|awk -F, '{print $(NF-1)}'|sort -g|head -1)";MIN_Y="$(grep ",$char_name," multi-kill-same-mobs-list|awk -F, '{print $NF}'|sort -g|head -1)";echo "$char_name,$KILLS,$MAX_X,$MAX_Y,$MIN_X,$MIN_Y,$(($MAX_X-$MIN_X)),$(($MAX_Y-$MIN_Y)),$GOT_TIMES";done > multi-kill-same-mobs-locations

#	awk -F, '$2>1000 && $7<150 && $8<150 {print }' multi-kill-same-mobs-locations |sort -t , -k 3|awk -F, '{print $1","$2","$7","$8","$9","$2/$9}'|sort -t , -k 2 -g|awk -F, '$6 > 10 { print $1",_SET_NUMBER_,1,In 2 hours: player <b>"$1"</b>(WZ__WZ_NUMBER__) killed <b>"$2"</b> mobs move around <b>"$3"</b>x<b>"$4"</b> area.(avg/"$6" kill per location)"}'|sed "s/_SET_NUMBER_/$(get_set $(awk -F/ '{print $NF}' <<< "$PWD"))/g;s/__WZ_NUMBER__/$(awk -F/ '{print $NF}' <<< "$PWD"|sed 's/[a-zA-Z]//g')/g"


#same-place
	LC_ALL=C sed ':x;N;$!bx;s/\n/|/g;s/|\([\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x20]\)/\n\1/g' $(ls -tr Attrib*.log.*|tail -2)|grep -v ",Z:[0-9][0-9][0-9]:"|egrep "$(date -d "-1 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date -d "-2 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date -d "-3 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date +"%Y/%m/%d %H:").....,EXP:[0-9]+"|egrep "$(LC_ALL=C sed ':x;N;$!bx;s/\n/|/g;s/|\([\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x20]\)/\n\1/g' $(ls -tr Attrib*.log.*|tail -2)|grep -v ",Z:[0-9][0-9][0-9]:"|egrep "$(date -d "-1 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date -d "-2 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date -d "-3 hour" +"%Y/%m/%d %H:").....,EXP:[0-9]+|$(date +"%Y/%m/%d %H:").....,EXP:[0-9]+"|awk -F: '{print ",Z:"$(NF-3)":.*:"$(NF-1)":"$NF"$"}' |sort -g|uniq -c|awk '$1>50 {print}'|sort -g|sed 's/^........//g'|tr '\n' '|'|sed 's/|$//g')"|sort -k 8 -t :|awk -F: '{print $(NF-5)","$(NF-4)" NODE:"$(NF-3)",X:"$(NF-1)",Y:"$NF}'|sort -g|uniq -cd|grep -v "^     " > multi-kill-same-place ; for char_id in `cat multi-kill-same-place|awk -F, '{print $1}'|sed 's/^........//g'|sort|uniq -c|grep -v "^      [0-2] "|awk '{print $2}'`;do char_name="$(grep $char_id, multi-kill-same-place|awk -F, '{print $2}'|head -1)";total_kill="$(($(grep $char_id, multi-kill-same-place|awk '{print $1"+"}')0))";echo -n "$char_name,_SET_NUMBER_,$KICK_BOTTING,In 3 hours: <b>$char_name</b>(WZ<b>$(awk -F/ '{print $NF}' <<< "$PWD"|sed 's/[a-zA-Z]//g')</b>) killed more than 300 mobs(total:<b>$total_kill</b>) in these positions:<br></pre>";grep ",$char_name," multi-kill-same-place|awk '{print "Killed:"$1" at "$3}'|sed 's/,/ /g'|tr '\n' '|'|sed 's/|/<br>/g;s/<br>$/<\/pre>/g';echo;done|sed "s/_SET_NUMBER_/$(get_set $(awk -F/ '{print $NF}' <<< "$PWD"))/g"

done
