#include "version.h"
#include<string.h>
#include<stdlib.h>
#include <time.h>
#include "buf.h"
#include"object.h"
#include"char.h"
#include"char_base.h"
#include"char_data.h"
#include"battle.h"
#include"battle_event.h"
#include"battle_command.h"
#include"battle_ai.h"
#include"configfile.h"
#include"lssproto_serv.h"
#include"encount.h"
#include"enemy.h"
#include"handletime.h"
#include"readmap.h"
#include"pet_skill.h"
#include "npcutil.h"
#include "magic.h"
#include "npc_npcenemy.h"
#include "log.h"
#include "pet_skillinfo.h"
#include "anim_tbl.h"
#include "common.h"
#include "battle_magic.h"
#ifdef _Item_ReLifeAct
#include "item.h"
#endif
#include "correct_bug.h"
#ifdef _AUTO_PK
#include "npc_autopk.h"
#endif
//#define DANTAI
static int Total_BattleNum=0;
BATTLE *BattleArray;
int BATTLE_battlenum;
static int BATTLE_searchCnt = 0;
#ifdef _PET_LIMITLEVEL //ANDY_ADD
void Pet_Check_Die( int petindex);
#endif
static int BATTLE_SearchTask( void );
static int BATTLE_Battling( int battleindex );
#ifdef _Item_ReLifeAct
BOOL CHECK_ITEM_RELIFE( int battleindex, int toindex);
#endif
#ifdef _LOSE_FINCH_
BOOL CHECK_PET_RELIFE( int battleindex, int petindex);
#endif
char szAllBattleString[BATTLE_STRING_MAX];
#ifdef _OTHER_MAGICSTAUTS
void BATTLE_MagicStatusSeq( int charaindex );
#endif
//Terry 2001/11/28
char szBattleString[512];
char *pszBattleTop,
*pszBattleLast;
char szBadStatusString[1024];
int gWeponType;
float gDamageDiv;
int gItemCrushRate = 400000;
int BoomerangVsTbl[4][5] = {
{ 4+5*0,2+5*0,0+5*0,1+5*0,3+5*0 },
{ 4+5*1,2+5*1,0+5*1,1+5*1,3+5*1 },
{ 4+5*2,2+5*2,0+5*2,1+5*2,3+5*2 },
{ 4+5*3,2+5*3,0+5*3,1+5*3,3+5*3 },
};
void BATTLE_BadStatusAllClr( int charaindex )
{
int i ;
for( i = 1; i < BATTLE_ST_END; i ++ ){
CHAR_setWorkInt( charaindex, StatusTbl[i], 0 );
}
#ifdef _OTHER_MAGICSTAUTS
for( i = 1; i < MAXSTATUSTYPE; i++ ){
CHAR_setWorkInt( charaindex, MagicTbl[i], 0);
CHAR_setWorkInt( charaindex, CHAR_OTHERSTATUSNUMS, 0);
}
#endif
#ifdef _IMPRECATE_ITEM
for( i=0; i<3; i++) {
CHAR_setWorkInt( charaindex, CHAR_WORKIMPRECATENUM1+i, 0 );
}
#endif
#ifdef _PETSKILL_SETDUCK
CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCK, 0);
CHAR_setWorkInt( charaindex, CHAR_MYSKILLDUCKPOWER, 0 );
#ifdef _MAGICPET_SKILL
CHAR_setWorkInt( charaindex, CHAR_MYSKILLSTR, 0);
CHAR_setWorkInt( charaindex, CHAR_MYSKILLSTRPOWER, 0 );
CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGH, 0);
CHAR_setWorkInt( charaindex, CHAR_MYSKILLTGHPOWER, 0 );
CHAR_setWorkInt( charaindex, CHAR_MYSKILLDEX, 0);
CHAR_setWorkInt( charaindex, CHAR_MYSKILLDEXPOWER, 0 );
CHAR_setWorkInt( charaindex, CHAR_MAGICPETMP, 0 );
#endif
#endif
CHAR_setFlg( charaindex, CHAR_ISDIE, 0 );
#ifdef _BATTLE_PROPERTY
{
Char *ch;
ch = CHAR_getCharPointer( charaindex);
if( ch == NULL ) return;
strcpysafe( ch->charfunctable[CHAR_BATTLEPROPERTY].string,
sizeof( ch->charfunctable[CHAR_BATTLEPROPERTY]), "");//战斗
CHAR_constructFunctable( charaindex);
}
#endif
#ifdef _PETSKILL_BECOMEPIG
if( CHAR_getInt( charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER )
{
for( i =0; i < CHAR_MAXPETHAVE; i++){
int pindex = CHAR_getCharPet( charaindex, i );
if( !CHAR_CHECKINDEX( pindex ) )
continue;
CHAR_setInt( pindex, CHAR_BECOMEPIG, -1 );
}
}
#endif
}
int BATTLE_getTopBattle( int battleindex )
{
BATTLE *pBattleTop;
if( BATTLE_CHECKINDEX( battleindex ) == FALSE ) return -1;
pBattleTop = &BattleArray[battleindex];
while( pBattleTop != NULL ){
pBattleTop = BattleArray[battleindex].pBefore;
}
if( BATTLE_CHECKINDEX( pBattleTop->battleindex ) == FALSE ){
return -1;
}else{
return pBattleTop->battleindex;
}
}
static int BATTLE_getBattleFieldNo( int floor, int x, int y )
{
int tile[2], map[3], iRet;
if( !MAP_getTileAndObjData( floor, x, y, &tile[0], &tile[1] ) )
return FALSE;
map[0] = MAP_getImageInt( tile[0], MAP_BATTLEMAP );
map[1] = MAP_getImageInt( tile[0], MAP_BATTLEMAP2 );
map[2] = MAP_getImageInt( tile[0], MAP_BATTLEMAP3 );
iRet = map[RAND( 0, 2 )];
return iRet;
}
void BATTLE_BadStatusString( int defNo, int status )
{
char szWork[256];
if( status < 1 || status >= BATTLE_ST_END ){
status = 0;
}
sprintf( szWork, "BM|%X|%X|", defNo, status );
strncat( szBadStatusString, szWork, sizeof( szBadStatusString ) );
}
#ifdef _ATTACK_MAGIC
static int CharTableIdx[20][2] =
{
{ 3 , 2 } , { 3 , 1 } , { 3 , 3 } , { 3 , 0 } , { 3 , 4 } ,
{ 2 , 2 } , { 2 , 1 } , { 2 , 3 } , { 2 , 0 } , { 2 , 4 } ,
{ 0 , 2 } , { 0 , 1 } , { 0 , 3 } , { 0 , 0 } , { 0 , 4 } ,
{ 1 , 2 } , { 1 , 1 } , { 1 , 3 } , { 1 , 0 } , { 1 , 4 }
};
typedef int ( *FUNCSORTLOC )( const void* , const void* );
static int SortLoc( const int *pEle1 , const int *pEle2 )
{
int ele1basex , ele1basey;
int ele2basex , ele2basey;
ele1basex = CharTableIdx[*pEle1][1];
ele1basey = CharTableIdx[*pEle1][0];
ele2basex = CharTableIdx[*pEle2][1];
ele2basey = CharTableIdx[*pEle2][0];
if( *pEle1 >= 10 ){
if( ele1basey != ele2basey )
return ( ele1basey - ele2basey );
return ( ele1basex - ele2basex );
}else{ // 右下方
if( ele1basey != ele2basey )
return ( ele2basey - ele1basey );
return ( ele2basex - ele1basey );
}
return 0;
}
#endif
int BATTLE_MultiList( int battleindex, int toNo, int ToList[] )
{
int j , i , cnt=0,nLife = 0,nLifeArea[10];
#ifdef _ATTACK_MAGIC
// 单人攻击
if(0 <= toNo && toNo <= 19){
memset(nLifeArea,-1,sizeof(nLifeArea));
// 如果被攻击者是右下方的人
if(toNo >= 0 && toNo <= 9){
for(i=0;i<10;i++){
// 确定活着的人数,并记录活着的人的号码
if(BATTLE_TargetCheck(battleindex,i) == TRUE) nLifeArea[nLife++] = i;
}
}
// 如果被攻击者是左上方的人
if(toNo >= 10 && toNo <= 19){
for(i=10;i<20;i++){
// 确定活着的人数,并记录活着的人的号码
if(BATTLE_TargetCheck(battleindex,i) == TRUE) nLifeArea[nLife++] = i;
}
}
// 全死(虽然不太可能,但..)
if(nLife == 0){
print("\nAll die!!");
return -1;
}else{
// 被攻击的对象已经死亡或不在战场上
if(BATTLE_TargetCheck(battleindex,toNo) == FALSE)
// 随机找一只来打
while((toNo = nLifeArea[rand()%10]) == -1);
}
ToList[0] = toNo;
ToList[1] = -1;
cnt = 1;
}
// 右下後一列攻击
else if( TARGET_SIDE_0_B_ROW == toNo ){
for( j = 0 , i = 0 ; i < SIDE_OFFSET / 2 ; i++ ){
if( TRUE == BATTLE_TargetCheck( battleindex , i ) ){
ToList[j] = i;
j++;
}
}
ToList[j] = -1;
cnt = j;
// 如果这一排都没有人可以打
if(j == 0){
// 换前一排
for( j = 0 , i = SIDE_OFFSET / 2 ; i < SIDE_OFFSET ; i++ ){
if( TRUE == BATTLE_TargetCheck( battleindex , i ) ){
ToList[j] = i;
j++;
}
}
ToList[j] = -1;
cnt = j;
// 如果全死
if(j == 0) return -1;
toNo = TARGET_SIDE_0_F_ROW;
}
}
// 右下前一列攻击
else if( TARGET_SIDE_0_F_ROW == toNo )
{
for( j = 0 , i = SIDE_OFFSET / 2 ; i < SIDE_OFFSET ; i++ )
{
if( TRUE == BATTLE_TargetCheck( battleindex , i ) )
{
ToList[j] = i;
j++;
}
}
ToList[j] = -1;
cnt = j;
// 如果这一排都没有人可以打
if(j == 0)
{
// 换後一排
for( j = 0 , i = 0 ; i < SIDE_OFFSET / 2 ; i++ )
{
if( TRUE == BATTLE_TargetCheck( battleindex , i ) )
{
ToList[j] = i;
j++;
}
}
ToList[j] = -1;
cnt = j;
// 如果全死
if(j == 0) return -1;
toNo = TARGET_SIDE_0_B_ROW;
}
}
// 左下後一列攻击
else if( TARGET_SIDE_1_B_ROW == toNo )
{
for( j = 0 , i = SIDE_OFFSET ; i < SIDE_OFFSET + SIDE_OFFSET / 2 ; i++ )
{
if( TRUE == BATTLE_TargetCheck( battleindex , i ) )
{
ToList[j] = i;
j++;
}
}
ToList[j] = -1;
cnt = j;
// 如果这一排都没有人可以打
if(j == 0)
{
// 换前一排
for( j = 0 , i = SIDE_OFFSET + SIDE_OFFSET / 2 ; i < SIDE_OFFSET * 2 ; i++ )
{
if( TRUE == BATTLE_TargetCheck( battleindex , i ) )
{
ToList[j] = i;
j++;
}
}
ToList[j] = -1;
cnt = j;
评论0