Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
*
* 背包内道具移动
* @param string $former 源位置格子号
* @param int $target 目标位置格子号
*/
public function MoveItemAction($former, $target)
{
$former = trim($former);
$target = intval($target);
if(!$former || $target < 1)
{
return $this->_view->error(MLanguages::COM__PARAMETERS_NOT_LEGAL); //参数异常;
}
//获取道具信息
$former_item = $this->__mItems->getNumberItem($former);
if(!$former_item)
{
return $this->_view->error(MLanguages::PACK__NOT_EXIST); //使用道具不存在;
}
$former_md5id = $former_item['md5_id'];
$former_num = $former_item['number'];
$former_base = $former_item['item_id'];
$former_sup = $former_item['superpose'];
//开启事务
$this->__mRole->beginTrans();
$target_item = $this->__mItems->getNumberItem($target);
$i = 0;
$former_change = 0;
$target_change = 0;
$this->__mItems->setChannel('11', MChannel::ITEM__MOVE_ITEM);
if(count($target_item) > 0)
{
$target_item['number'] = $former_num;
$target_base = $target_item['item_id'];
$target_sup = $target_item['superpose'];
$base_item = $this->__Config->getConfig('items', $target_base, 'base_id');
//相同道具的处理
if(($target_base == $former_base) && ($base_item['is_stack'] == 1)&&$target_item['is_band']==1)
{
$former_item['superpose'] += $target_sup;
$former_change = $target_sup;
if($former_item['superpose'] >= $base_item['stack_number'])
{
$former_change = $base_item['stack_number'] - $former_sup;
$former_item['superpose'] = $base_item['stack_number'];
$target_item['superpose'] = ($target_sup + $former_sup) - $base_item['stack_number'];
$target_change = $target_sup - $target_item['superpose'];
}
else
{
$i = 1;
}
//绑定移动到
if($former_item['is_band'] == 0 && $target_item['is_band'] == 1)
{
$former_item['is_band'] = 1;
$target_item['is_band'] = 0;
}
}
$this->__mItems->setMd5Id($target_item['md5_id']);
$this->__mItems->setItem($target_item);
if($i == 1 || $target_item['superpose'] == 0)
{
$this->__mItems->setChannel('5', MChannel::ITEM__MOVE_ITEM);
if(!$this->__mItems->delItem())
{
$this->__mRole->rollBack();
return $this->_view->error(MLanguages::COM__OPERATION_FAILURE); //操作失败;
}
}
else
{
if($target_change != 0)
{
$this->__mItems->setNumber($target_sup, $target_change);
}
if(!$this->__mItems->editItem())
{
$this->__mRole->rollBack();
return $this->_view->error(MLanguages::COM__OPERATION_FAILURE); //操作失败;
}
}
}
$former_item['number'] = $target;
$this->__mItems->setMd5Id($former_md5id);
$this->__mItems->setItem($former_item);
// $this->__mItems->setMd5Id($target_item['md5_id']);
// $this->__mItems->setItem($target_item);
if($former_item['superpose'] == 0)
{
$this->__mItems->setChannel('5', MChannel::ITEM__MOVE_ITEM);
if(!$this->__mItems->delItem())
{
$this->__mRole->rollBack();
return $this->_view->error(MLanguages::COM__OPERATION_FAILURE); //操作失败;
}
}
else
{
if($former_change != 0)
{
$this->__mItems->setNumber($former_sup, $former_change);
}
if(!$this->__mItems->editItem())
{
$this->__mRole->rollBack();
return $this->_view->error(MLanguages::COM__OPERATION_FAILURE); //操作失败;
}
}
$this->__mRole->commit();
return $this->_view->success(MLanguages::COM__OPERATION_SUCCESS); //操作成功
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.