You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

155 lines
5.2 KiB

using System;
using System.Collections.Generic;
namespace ET
{
public static class CabinHelper
{
public static async ETTask<int> GoCabin(Unit unit, People people, Cabin cabin)
{
try
{
C2M_GoCabin msg = new C2M_GoCabin() { PeopleId = people.Id, CabinId = cabin.Id };
M2C_GoCabin resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_GoCabin;
if (resp.Error == ErrorCode.ERR_Success)
{
cabin.PeoplePrepare(people.Id);
PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_CABIN, cabin.Id);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> ArriveCabin(Unit unit, People people, Cabin cabin)
{
try
{
C2M_ArriveCabin msg = new C2M_ArriveCabin() { PeopleId = people.Id, CabinId = cabin.Id };
M2C_ArriveCabin resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_ArriveCabin;
if (resp.Error == ErrorCode.ERR_Success)
{
cabin.PeopleArrive(people.Id);
people.SetBehaveType(ConstBehaveType.BEHAVE_CABIN);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> AddFarmland(Unit unit, Cabin cabin, List<long> farmlandIds)
{
try
{
C2M_CabinAddFarmland msg = new C2M_CabinAddFarmland() { CabinId = cabin.Id, FarmlandIds = farmlandIds };
M2C_CabinAddFarmland resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinAddFarmland;
foreach (var v in resp.FarmlandIds)
{
cabin.AddFarmland(v);
var farmland = unit.GetGrandChild<Farmland>(v);
if (farmland != null)
{
farmland.SetCabinId(cabin.Id);
}
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> CabinSeed(Unit unit, Farmland farmland, int cropCfgId)
{
try
{
C2M_CabinSeed msg = new C2M_CabinSeed() { CropCfgId = cropCfgId, FarmlandId = farmland.Id };
M2C_CabinSeed resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinSeed;
if (resp.Error == ErrorCode.ERR_Success)
{
CabinOperate.CabinSeed(unit, farmland, cropCfgId);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> CabinUpdateFarmlands(Unit unit, Cabin cabin, List<long>farmlandIds)
{
try
{
C2M_CabinUpdateFarmlands msg = new C2M_CabinUpdateFarmlands() { CabinId = cabin.Id, FarmlandIds = farmlandIds };
M2C_CabinUpdateFarmlands resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinUpdateFarmlands;
if (resp.Error == ErrorCode.ERR_Success)
{
CabinOperate.CabinUpdateFarmlands(unit,cabin,farmlandIds);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> CabinHarvest(Unit unit, Farmland farmland)
{
try
{
C2M_CabinHarvest msg = new C2M_CabinHarvest() { FarmlandId = farmland.Id};
M2C_CabinHarvest resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinHarvest;
if (resp.Error == ErrorCode.ERR_Success)
{
CabinOperate.CabinHarvest(unit,farmland);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
}
}