装备强化系统主要代码

  • A+
所属分类:源码教程
装备强化系统主要代码

功能描述:
  可对物品进行升级,升级成功后物品将显示+1,可装物品升级到+10,等级越高,升级机率越低,如果升级失败,将下降等级。
  每次成功,物品属性将会相对应提升,如果功+10的武器,升级成功,该武器的功将提示1的攻击力。
  攻击力,防卸力,速度则每级提升都加1点。
void ITEM_useEnhancedItem_WindowResult( int charaindex, int seqno, int select, char * data)
{
  int page = 0;
  int fd;
  char buf[2048];
  char message[1024];
  if( select == WINDOW_BUTTONTYPE_CANCEL) return;

  fd = getfdFromCharaIndex( charaindex);
  if( fd == - 1 )
  {
    return;
  }

  if( seqno != CHAR_WINDOWTYPE_SELECTENHANCEDITEM_ENHANCED )
  {
    if( select == WINDOW_BUTTONTYPE_NEXT )
    {
      page = 1;
    }
    else if( select == WINDOW_BUTTONTYPE_PREV )
    {
      page = -1;
    }
    if( select == WINDOW_BUTTONTYPE_NEXT || select == WINDOW_BUTTONTYPE_PREV )
    {
      int winno = seqno - CHAR_WINDOWTYPE_SELECTENHANCEDITEM_PAGE1;
      winno += page;
      if( winno < 0 ) winno = 0;
      if( winno > 3 ) winno = 3;
      ITEM_useEnhancedItem_PrintWindow( charaindex, winno );
    }
    else
    {
      char  message[1024];
      char  buf[2048];
      char  haveitemindex = CHAR_getWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM);
      int    itemindex;
      if( haveitemindex == -1 )
      {
        haveitemindex = (seqno - CHAR_WINDOWTYPE_SELECTENHANCEDITEM_PAGE1 ) * 5 + ( atoi(data)-1);
        CHAR_setWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM, haveitemindex);
      }
      itemindex = CHAR_getItemIndex( charaindex, haveitemindex);

      snprintf( message, sizeof( message),
              "真的要对( %s )进行强化嘛?\n如果失败原有强化等级将会下降!\n",ITEM_getChar( itemindex, ITEM_NAME));

      lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OKCANCEL, CHAR_WINDOWTYPE_SELECTENHANCEDITEM_ENHANCED, -1, makeEscapeString( message, buf, sizeof(buf)));
    }
  }
  else
  {
    char haveitemindex = CHAR_getWorkInt( charaindex, CHAR_WORKRENAMEITEMNUM );
    int itemindex = CHAR_getItemIndex( charaindex, haveitemindex );//获得需强化道具索引

    if( !ITEM_CHECKINDEX( itemindex ) )//索引不存在返回
    {
      print( "%s %d err\n", __FILE__, __LINE__);
      return;
    }

    int itemlevel = CHAR_getInt( itemindex, ITEM_ENHANCED );

    if( itemlevel >= 10 )
    {
      snprintf( message, sizeof( message), "( %s )已到强化极限,无法再进行强化!\n", ITEM_getChar( itemindex, ITEM_NAME ));
      lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, CHAR_WINDOWTYPE_SELECTENHANCEDITEM_ENHANCED_ATTENTION, -1, makeEscapeString( message, buf, sizeof(buf)));
      return;
    }
    else
    {
      srand( (int)time(0) );
      char buf1[256];
      if( rand() % 10000 < 25 )//成功+1
      {
        ITEM_setInt( itemindex, ITEM_MODIFYATTACK, ITEM_getInt( itemindex, ITEM_MODIFYATTACK ) + 1 );//攻+1
        ITEM_setInt( itemindex, ITEM_MODIFYDEFENCE, ITEM_getInt( itemindex, ITEM_MODIFYDEFENCE ) + 1 );//防+1
        ITEM_setInt( itemindex, ITEM_MODIFYQUICK, ITEM_getInt( itemindex, ITEM_MODIFYQUICK ) + 1 );//敏+1
        ITEM_setInt( itemindex, ITEM_ENHANCED, ITEM_getInt( itemindex, ITEM_ENHANCED ) + 1 );//强化等级+1
        //装备改名
        char *itemname = ITEM_getChar( itemindex, ITEM_NAME );//获得装备原名
        sprintf( buf1, "+%d", ITEM_getInt( itemindex, ITEM_ENHANCED ) );
        strcat( buf1, itemname );
        ITEM_setChar( itemindex, ITEM_SECRETNAME, buf1 );

        snprintf( message, sizeof( message), "成功!( %s )的能力提升!\n", ITEM_getChar( itemindex, ITEM_NAME ));
        lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, CHAR_WINDOWTYPE_SELECTENHANCEDITEM_ENHANCED_ATTENTION, -1, makeEscapeString( message, buf, sizeof(buf)));
        return;
      }
      else//失败-1
      {
        if( ITEM_getInt( itemindex, ITEM_ENHANCED ) > 0 )//如果强化等级非0
        {
          ITEM_setInt( itemindex, ITEM_MODIFYATTACK, ITEM_getInt( itemindex, ITEM_MODIFYATTACK ) - 1 );//攻-1
          ITEM_setInt( itemindex, ITEM_MODIFYDEFENCE, ITEM_getInt( itemindex, ITEM_MODIFYDEFENCE ) - 1 );//防-1
          ITEM_setInt( itemindex, ITEM_MODIFYQUICK, ITEM_getInt( itemindex, ITEM_MODIFYQUICK ) - 1 );//敏-1
          ITEM_setInt( itemindex, ITEM_ENHANCED, ITEM_getInt( itemindex, ITEM_ENHANCED ) - 1 );//强化等级-1
          //装备改名
          char *itemname = ITEM_getChar( itemindex, ITEM_NAME );//获得装备原名
          sprintf( buf1, "+%d", ITEM_getInt( itemindex, ITEM_ENHANCED ) );
          strcat( buf1, itemname );
          ITEM_setChar( itemindex, ITEM_SECRETNAME, buf1 );
        }
        snprintf( message, sizeof( message), "失败!( %s )的能力降低!\n", ITEM_getChar( itemindex, ITEM_NAME ));
        lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE, WINDOW_BUTTONTYPE_OK, CHAR_WINDOWTYPE_SELECTENHANCEDITEM_ENHANCED_ATTENTION, -1, makeEscapeString( message, buf, sizeof(buf)));
      }

    }
  }
}
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

您必须登录才能发表评论!