Example #1
0
void GameScene::createPlayerItem(cocos2d::Ref *pSender)
{
    auto mapObj = static_cast<MapObject*>(pSender);
    auto row = mapObj->getRow(),col = mapObj->getCol();
    //mapObj->release();
    auto itemId = rand()%5;
    if(itemId<5)
    {
        auto playerItemType = GameManager::getInstance()->getPlayerItems().at(itemId);
        auto item = PlayerItem::create();
        item->setItemType(playerItemType);
        item->setZOrder(row*10);
        item->setIdx(itemId);
        item->setPosition(mapObj->convertCoordinate2Point(Point(col,row)));
        GameManager::getInstance()->getMapTileLayer()->addChild(item);
    }
}
Variant &FuncScopeVariableEnvironment::getVar(CStrRef s, SuperGlobal sg) {
  if (sg == SgNormal) {
    Variant *v = m_alist.getPtr(s);
    if (!v) {
      v = &m_alist.append(s);
      const Block::VariableIndices &variableIndices = m_func->varIndices();
      Block::VariableIndices::const_iterator it = variableIndices.find(s);
      if (it != variableIndices.end()) {
        setIdx(it->second.idx(), v);
      }
    }
    return *v;
  }
  if (sg == SgGlobals) {
    Variant &v = m_alist.append(s);
    v = get_global_array_wrapper();
    return v;
  }
  return get_globals()->get(s);
}
Example #3
0
File: core.c Project: sfwc/Gospel
void setEnv(continuation c, obj o)            { setIdx(c, 4, o); }
Example #4
0
File: core.c Project: sfwc/Gospel
void setUnevaluated(continuation c, vector v) { setIdx(c, 3, v); }
Example #5
0
File: core.c Project: sfwc/Gospel
void setEvaluated(continuation c, vector v)   { setIdx(c, 2, v); }
Example #6
0
File: core.c Project: sfwc/Gospel
vector setThreadReceiver(vector thread, obj o) {
  setIdx(threadContinuation(thread), 6, o);
  return thread;
}
Example #7
0
bool ISitableRoom::onMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nPlayerSessionID )
{
	if ( IRoom::onMessage(prealMsg,eSenderPort,nPlayerSessionID) )
	{
		return true ;
	}

	switch ( prealMsg->usMsgType )
	{
	case MSG_REQ_CUR_GAME_OFFSET:
		{
			auto pPlayer = getSitdownPlayerBySessionID(nPlayerSessionID) ;
			if ( pPlayer )
			{
				stMsgReqRobotCurGameOffsetRet msgback ;
				msgback.nCurGameOffset = pPlayer->getTotalGameOffset();
				sendMsgToPlayer(&msgback,sizeof(msgback),nPlayerSessionID) ;
				LOGFMTD("robot req cur offset = %d , uid = %u",msgback.nCurGameOffset,pPlayer->getUserUID());
			}
		}
		break;
	case MSG_ADD_TEMP_HALO:
		{
			auto pPlayer = getPlayerBySessionID(nPlayerSessionID) ;
			if ( pPlayer == nullptr )
			{
				LOGFMTE("not in room player add temp halo session id = %u",nPlayerSessionID);
				break;
			}

			//if ( pPlayer->nPlayerType == ePlayer_Normal )
			//{
			//	LOGFMTE("normal can not add temp halo");
			//	break;
			//}

			stMsgAddTempHalo* pRet = (stMsgAddTempHalo*)prealMsg ;
			if ( 0 == pRet->nTargetUID )
			{
				pRet->nTargetUID = pPlayer->nUserUID ;
			}

			auto psitpp = getSitdownPlayerByUID(pRet->nTargetUID) ;
			if ( psitpp )
			{
				psitpp->setTempHaloWeight(pRet->nTempHalo);
				LOGFMTD("uid = %u add temp halo = %u",pRet->nTargetUID,pRet->nTempHalo) ;
			}
			else
			{
				LOGFMTE("uid = %u not sit down why add temp halo",pPlayer->nUserUID);
			}
		}
		break;
	case MSG_PLAYER_SITDOWN:
		{
			stMsgPlayerSitDownRet msgBack ;
			msgBack.nRet = 0 ;

			stStandPlayer* pPlayer = getPlayerBySessionID(nPlayerSessionID) ;
			if ( !pPlayer )
			{
				LOGFMTE("palyer session id = %d ,not in this room so , can not sit down",nPlayerSessionID) ;
				msgBack.nRet = 3 ;
				sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ;
				break; 
			}

			auto pp = getSitdownPlayerByUID(pPlayer->nUserUID);
			if ( pp )
			{
				LOGFMTE("session id = %d , already sit down , don't sit down again",nPlayerSessionID ) ;
				msgBack.nRet = 4 ;
				sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ;
				break;
			}

			stMsgPlayerSitDown* pRet = (stMsgPlayerSitDown*)prealMsg ;
			if ( pRet->nTakeInCoin == 0 || pRet->nTakeInCoin > pPlayer->nCoin)
			{
				pRet->nTakeInCoin = pPlayer->nCoin ;
			}

			if ( pRet->nTakeInCoin < coinNeededToSitDown() )
			{
				msgBack.nRet = 1 ;
				sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ;
				break; 
			}

			if ( isSeatIdxEmpty(pRet->nIdx) == false )
			{
				msgBack.nRet = 2 ;
				sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ;
				break; 
			}

			auto sitDownPlayer = getReuseSitableRoomPlayerObject() ;
			sitDownPlayer->reset(pPlayer) ;
			pPlayer->nCoin -= pRet->nTakeInCoin ;
			sitDownPlayer->setCoin(pRet->nTakeInCoin) ;
			sitDownPlayer->doSitdown(pRet->nIdx) ;
			sitDownPlayer->setIdx(pRet->nIdx);
			sitDownPlayer->setState(eRoomPeer_WaitNextGame );
			m_vSitdownPlayers[pRet->nIdx] = sitDownPlayer ;

			// tell others ;
			stMsgRoomSitDown msgSitDown ;
			msgSitDown.nIdx = sitDownPlayer->getIdx() ;
			msgSitDown.nSitDownPlayerUserUID = sitDownPlayer->getUserUID() ;
			msgSitDown.nTakeInCoin = sitDownPlayer->getCoin() ;
			sendRoomMsg(&msgSitDown,sizeof(msgSitDown));

			onPlayerSitDown(sitDownPlayer) ;

			if ( pPlayer->nPlayerType == ePlayer_Robot )
			{
				LOGFMTD("robot uid = %d enter room",sitDownPlayer->getUserUID()) ;
				m_pRobotDispatchStrage->onRobotJoin(sitDownPlayer->getSessionID());
			}
		}
		break;
	case MSG_PLAYER_STANDUP:
		{
			stMsgPlayerStandUpRet msgBack ;
			msgBack.nRet = 0 ;
			auto player = getSitdownPlayerBySessionID(nPlayerSessionID) ;
			if ( player == nullptr )
			{
				msgBack.nRet = 1 ;
				sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ;
				break; 
			}
			onPlayerWillStandUp(player);
		}
		break;
	default:
		return false;
	}
	return true ;
}